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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  vector<int> vec(N + 10);
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> vec.at(i);
  }
  // 入力終わり
  int sum_a = 0, sum_b = 0;
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  for (int i = 0; i < N; i += 2) {
    sum_a += vec.at(i);
  }
  for (int i = 1; i < N; i += 2) {
    sum_b += vec.at(i);
  }
  cout << sum_a - sum_b << endl;

  /*
  for(int i=0; i<N+10; i++){
      cout << vec.at(i) << endl;
  }
  */
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  vector<int> vec(N + 100);
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> vec.at(i);
  }
  // 入力終わり
  int sum_a = 0, sum_b = 0;
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  for (int i = 0; i < N; i += 2) {
    sum_a += vec.at(i);
  }
  for (int i = 1; i < N; i += 2) {
    sum_b += vec.at(i);
  }
  cout << sum_a - sum_b << endl;

  /*
  for(int i=0; i<N+10; i++){
      cout << vec.at(i) << endl;
  }
  */
}
Problem p03434 (C++)

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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end()); // 大きい順に変換

  int X = 0, Y = 0;
  for (int i = 0; i < N; i++) {
    if (i = 0)
      X += A.at(i);
    else
      Y += A.at(i);
  }

  cout << X - Y << endl;
}


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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end()); // 大きい順に変換

  int X = 0, Y = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0)
      X += A.at(i);
    else
      Y += A.at(i);
  }

  cout << X - Y << endl;
}
Problem p03434 (C++)

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

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

  vector<int> vec(10);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  int Alice, Bob;
  Alice = 0;
  Bob = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      Alice += vec.at(i);
    }
    if (i % 2 == 1) {
      Bob += vec.at(i);
    }
  }

  cout << Alice - Bob << endl;
}


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

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

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  int Alice, Bob;
  Alice = 0;
  Bob = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      Alice += vec.at(i);
    }
    if (i % 2 == 1) {
      Bob += vec.at(i);
    }
  }

  cout << Alice - Bob << endl;
}
Problem p03434 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int ans = 0;
  int i = 0;
  while (vec.size() > 1) {
    ans = ans + vec.at(N - i - 1) - vec.at(N - i - 2);
    vec.pop_back();
    vec.pop_back();
    i++;
  }
  if (vec.size() == 1) {
    ans += vec.at(0);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int ans = 0;
  int i = 0;
  while (vec.size() > 1) {
    ans = ans + vec.at(N - i - 1) - vec.at(N - i - 2);
    vec.pop_back();
    vec.pop_back();
    i += 2;
  }
  if (vec.size() == 1) {
    ans += vec.at(0);
  }
  cout << ans << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
    cin >> vec[i];
  sort(vec.begin(), vec.end());
  int s, x;
  for (int i = 0; i < N - 2; i += 2) {
    x += vec[N - i - 1] - vec[N - i - 2];
    s = i + 2;
  }
  x += vec[N - s - 1];
  if (s == N - 2)
    x -= vec[0];
  cout << x << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
    cin >> vec[i];
  sort(vec.begin(), vec.end());
  int s = 0, x = 0;
  for (int i = 0; i < N - 2; i += 2) {
    x += vec[N - i - 1] - vec[N - i - 2];
    s = i + 2;
  }
  x += vec[N - s - 1];
  if (s == N - 2)
    x -= vec[0];
  cout << x << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

  for (int i = 0; i < N; i++)
    cin >> a.at(i);

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int A = 0, B = 0;

  for (int i = 0; i < (N + 1) / 2; i++) {
    A += a.at(2 * i);
    B += a.at(2 * i + 1);
  }

  cout << A - B << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  a.push_back(0);

  for (int i = 0; i < N; i++)
    cin >> a.at(i);

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int A = 0, B = 0;

  for (int i = 0; i < (N + 1) / 2; i++) {
    A += a.at(2 * i);
    B += a.at(2 * i + 1);
  }

  cout << A - B << endl;
}
Problem p03434 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define PI acos(-1.0)
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)

int N;
int A[100];
int res_a = 0;
int res_b = 0;

int main() {
  cin >> N;
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N, greater<int>());
  for (int i = 1; i <= N; ++i) {
    if (i %= 0) {
      res_a += A[i];
    } else {
      res_b += A[i];
    }
  }

  cout << res_a - res_b;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define PI acos(-1.0)
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)

int N;
int A[100];
int res_a = 0;
int res_b = 0;

int main() {
  cin >> N;
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N, greater<int>());
  for (int i = 0; i < N; ++i) {
    if (i % 2 == 0) {
      res_a += A[i];
    } else {
      res_b += A[i];
    }
  }

  cout << res_a - res_b;
  return 0;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int alice, bob;
  for (int i = 0; i < N / 2; i++) {
    alice += vec.at(i * 2);
    bob += vec.at(i * 2 - 1);
  }
  cout << alice - bob << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int alice, bob;
  alice = 0;
  bob = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      alice += vec.at(i);
    } else
      bob += vec.at(i);
  }
  cout << alice - bob << endl;
}
Problem p03434 (C++)

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

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> a;
  for (int i; i < n; i++)
    cin >> a.at(i);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0)
      ans += a.at(i);
    else
      ans -= a.at(i);
  }
  cout << ans << endl;
}

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

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> a(n);
  for (int i; i < n; i++)
    cin >> a.at(i);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0)
      ans += a.at(i);
    else
      ans -= a.at(i);
  }
  cout << ans << endl;
}
Problem p03434 (C++)

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

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

  vector<int> a;

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

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int Alice = 0, Bob = 0;

  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      Alice += a.at(i);
    } else {
      Bob += a.at(i);
    }
  }

  cout << Alice - Bob << endl;
}


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

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

  vector<int> a(N);

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

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int Alice = 0, Bob = 0;

  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      Alice += a.at(i);
    } else {
      Bob += a.at(i);
    }
  }

  cout << Alice - Bob << endl;
}
Problem p03434 (C++)

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

int main() {
  int N, A = 0, B = 0;
  cin >> N;
  vector<int> vec;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      A += vec.at(i);
    } else {
      B += vec.at(i);
    }
  }
  cout << A - B << endl;
}

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

int main() {
  int N, A = 0, B = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      A += vec.at(i);
    } else {
      B += vec.at(i);
    }
  }
  cout << A - B << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  int a[100] = {0};

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

  int aliceP = 0;
  int bobP = 0;

  std::sort(a, a + sizeof(a), std::greater<int>());

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

  std::cout << aliceP - bobP << std::endl;

  return 0;
}

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

int main() {
  int N;
  int a[100] = {0};

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

  int aliceP = 0;
  int bobP = 0;

  std::sort(a, a + N, std::greater<int>());

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

  std::cout << aliceP - bobP << std::endl;

  return 0;
}
Problem p03434 (C++)

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

int main() {
  int n, i, c = 0, d = 0;
  cin >> n;
  int a[i];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (i = 0; i < n; i++) {
    if (i % 2 == 0) {
      c += a[i];
    } else {
      d += a[i];
    }
  }
  cout << abs(c - d);
  return 0;
}

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

int main() {
  int n, i, c = 0, d = 0;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (i = 0; i < n; i++) {
    if (i % 2 == 0) {
      c += a[i];
    } else {
      d += a[i];
    }
  }
  cout << abs(c - d);
  return 0;
}
Problem p03434 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, al, bo;
  al = 0;
  bo = 0;
  cin >> n;
  vector<int> a(n);
  for (i = 0; i < n; ++i) {
    cin >> a.at(i);
  }
  sort(a.end(), a.begin());

  for (i = 0; i < n; ++i) {
    if (i % 2 == 0)
      al = al + a.at(i);
    else
      bo = bo + a.at(i);
  }
  cout << al - bo;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, al, bo;
  al = 0;
  bo = 0;
  cin >> n;
  vector<int> a(n);
  for (i = 0; i < n; ++i) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (i = 0; i < n; ++i) {
    if (i % 2 == 0)
      al = al + a.at(i);
    else
      bo = bo + a.at(i);
  }
  cout << al - bo;
  return 0;
}
Problem p03434 (C++)

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

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

  vector<int> vec;

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

  sort(vec.begin(), vec.end());    // 昇順にソート
  reverse(vec.begin(), vec.end()); // 降順にソート

  int sum1, sum2;
  sum1 = sum2 = 0;

  for (int i = 0; i < N; i += 2) {
    sum1 += vec.at(i);
  }
  for (int i = 1; i < N; i += 2) {
    sum2 += vec.at(i);
  }

  cout << sum1 - sum2 << endl;
}


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

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

  vector<int> vec(N);

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

  sort(vec.begin(), vec.end());    // 昇順にソート
  reverse(vec.begin(), vec.end()); // 降順にソート

  int sum1, sum2;
  sum1 = sum2 = 0;

  for (int i = 0; i < N; i += 2) {
    sum1 += vec.at(i);
  }
  for (int i = 1; i < N; i += 2) {
    sum2 += vec.at(i);
  }

  cout << sum1 - sum2 << endl;
}
Problem p03434 (C++)

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

  int n;

  scanf("%d", &n);

  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  sort(a.begin(), a.end());

  int al = 0;
  int sl = 0;

  for (int i = 0; i < n; i++) {
    if (i & 1)
      sl += a[i];
    else
      al += a[i];
  }

  printf("%d\n", (sl - al > 0) ? sl - al : -(sl - al));
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
vector<int> a;
int main() {

  int n;

  scanf("%d", &n);

  for (int i = 0, tmp; i < n; i++) {

    scanf("%d", &tmp);
    a.push_back(tmp);
  }

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

  int al = 0;
  int sl = 0;

  for (int i = 0; i < n; i++) {
    if (i & 1)
      sl += a[i];
    else
      al += a[i];
  }

  printf("%d\n", (sl - al > 0) ? sl - al : -(sl - al));
  return 0;
}
Problem p03434 (C++)

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

int main() {
  int N, Al = 0, Bo = 0;
  cin >> N;

  vector<int> v(N);
  for (int i = 0; i < N; i++) {

    cin >> v.at(i);
  }

  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  int Ans;

  int a = N % 2;

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

    Al += v.at(p);
  }

  if (a == 1) {

    Al += v.at(N);
  }

  for (int q = 1; q < N; q += 2) {

    Bo += v.at(q);
  }

  Ans = Al - Bo;

  cout << Ans << endl;
}

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

int main() {
  int N, Al = 0, Bo = 0;
  cin >> N;

  vector<int> v(N);
  for (int i = 0; i < N; i++) {

    cin >> v.at(i);
  }

  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  int Ans;

  int a = N % 2;

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

    Al += v.at(p);
  }

  for (int q = 1; q < N; q += 2) {

    Bo += v.at(q);
  }

  Ans = Al - Bo;

  cout << Ans << endl;
}
Problem p03434 (C++)

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

int main() {

  int N;
  cin >> N;
  vector<int> card(N + 3);
  for (int i = 0; i < N; i++) {
    cin >> card.at(i);
  }

  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());

  int A;
  for (int i = 0; i < N + 1 / 2; i++) {
    A += card.at(2 * i);
    A -= card.at(2 * i + 1);
  }
  cout << A << endl;
}

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

int main() {

  int N;
  cin >> N;
  vector<int> card(N + 3);
  for (int i = 0; i < N; i++) {
    cin >> card.at(i);
  }

  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());

  int A;
  for (int i = 0; i < (N + 1) / 2; i++) {
    A += card.at(2 * i);
    A -= card.at(2 * i + 1);
  }
  cout << A << endl;
}
Problem p03434 (C++)

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

int main() {
  int n;
  cin >> n;
  priority_queue<int> q;
  rep(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }
  int ali = 0;
  int bob = 0;
  while (q.size()) {
    ali += q.top();
    q.pop();
    bob += q.top();
    q.pop();
  }
  int ans = ali - bob;
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  priority_queue<int> q;
  rep(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }
  int ali = 0;
  int bob = 0;
  while (q.size()) {
    ali += q.top();
    q.pop();
    if (q.size() == 0)
      break;
    bob += q.top();
    q.pop();
  }
  int ans = ali - bob;
  cout << ans << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

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

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

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      ans += a.at(i);
    } else {
      ans -= a.at(i);
    }
  }

  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

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

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      ans += a.at(i);
    } else {
      ans -= a.at(i);
    }
  }

  cout << ans << endl;
}
Problem p03434 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
s = list(map(int, input().split()))
s.sort(reverse=True)
print(s[::2] - s[1::2])


Fixed submission:
n = int(input())
s = list(map(int, input().split()))
s.sort(reverse=True)
print(sum(s[::2]) - sum(s[1::2]))
Problem p03434 (C++)

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

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

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

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

  int sum = 0;
  for (int i = 0; i < N; i += 2) {
    sum += vec.at(i) - vec.at(i + 1);
  }

  cout << sum << endl;
}

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

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

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

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

  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      sum += vec.at(i);
    }

    if (i % 2 == 1) {
      sum -= vec.at(i);
    }
  }

  cout << sum << endl;
}
Problem p03434 (C++)

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

int main() {
  int n, a[10], ans = 0, tmp, cnt;

  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  while (1) {
    cnt = 0;
    for (int i = 0; i < n - 1; i++) {
      if (a[i] < a[i + 1]) {
        tmp = a[i];
        a[i] = a[i + 1];
        a[i + 1] = tmp;

        cnt++;
      }
    }
    if (cnt == 0) {
      break;
    }
  }

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

  std::cout << ans;

  return 0;
}

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

int main() {
  int n, a[100], ans = 0, tmp, cnt;

  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  while (1) {
    cnt = 0;
    for (int i = 0; i < n - 1; i++) {
      if (a[i] < a[i + 1]) {
        tmp = a[i];
        a[i] = a[i + 1];
        a[i + 1] = tmp;

        cnt++;
      }
    }
    if (cnt == 0) {
      break;
    }
  }

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

  std::cout << ans;

  return 0;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  int alice = 0, bob = 0;
  for (int j = 0; j < N; j += 2) {
    alice += A.at(j);
    if (N % 2 == 0 || j != N) {
      bob += A.at(j + 1);
    }
  }
  cout << alice - bob << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  int alice = 0, bob = 0;
  for (int j = 0; j < N; j += 2) {
    alice += A.at(j);
    if (N % 2 == 0 || j != N - 1) {
      bob += A.at(j + 1);
    }
  }
  cout << alice - bob << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());

  int alice, bob;
  alice = 0;
  bob = 0;
  for (int i = 0; i < N;) {
    alice += a.at(N - i - 1);
    bob += a.at(N - i - 2);
    i += 2;
  }
  cout << alice - bob << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());

  int alice, bob;
  alice = 0;
  bob = 0;
  for (int i = N; i > 1;) {
    alice += a.at(i - 1);
    bob += a.at(i - 2);
    i -= 2;
  }
  if (N % 2 == 1) {
    alice += a.at(0);
  }
  cout << alice - bob << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);

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

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

  int sum = 0;

  for (int i = 0; i < N; i++) {
    sum += vec.at(i);
    i++;
    sum -= vec.at(i);
  }

  cout << sum << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);

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

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

  int sum = 0;

  for (int i = 0; i < N; i++) {
    sum += (i & 1) ? -vec[i] : vec[i];
  }

  cout << sum << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> cards(N);
  for (int i = 0; i < N; i++) {
    cin >> cards.at(i);
  }
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  int A = 0;
  int B = 0;
  for (int i = 0; i < N; i += 2) {
    A = A + cards.at(i);
    B = B + cards.at(i + 1);
  }
  cout << A - B << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> cards(N);
  for (int i = 0; i < N; i++) {
    cin >> cards.at(i);
  }
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  int A = 0;
  int B = 0;
  if (N == N / 2 * 2) {
    for (int i = 0; i < N; i += 2) {
      A = A + cards.at(i);
      B = B + cards.at(i + 1);
    }
  } else {
    for (int i = 0; i < N - 1; i += 2) {
      A += cards.at(i);
      B += cards.at(i + 1);
    }
    A += cards.at(N - 1);
  }
  cout << A - B << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  for (int i = 0; i < N; i++) {
    cin >> card.at(i);
  }

  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  int A, B;

  for (int i = 0; i < N / 2; i++) {
    A += card.at(2 * i);
    B += card.at(2 * i + 1);
  }

  if (N % 2 == 1) {
    A += card.at(N);
  }

  cout << A - B << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  for (int i = 0; i < N; i++) {
    cin >> card.at(i);
  }

  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  int A, B;

  for (int i = 0; i < N / 2; i++) {
    A += card.at(2 * i);
    B += card.at(2 * i + 1);
  }

  if (N % 2 == 1) {
    A += card.at(N - 1);
  }

  cout << A - B << endl;
}
Problem p03434 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int i = 0;
  int res = 0;
  while (i <= n - 1) {
    res += a.at(i);
    res -= a.at(i + 1);
    i += 2;
  }
  cout << res << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int i = 0;
  int res = 0;
  while (i <= n - 1) {
    res += a.at(i);
    if (i + 1 <= n - 1) {
      res -= a.at(i + 1);
    }
    i += 2;
  }
  cout << res << endl;
}
Problem p03434 (C++)

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

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)

int N;
int A[100];

int main() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", A[i]);

  sort(A, A + N, greater<int>());
  int a = 0, b = 0;
  REP(i, N) {
    if (i % 2 == 0)
      a += A[i];
    else
      b += A[i];
  }

  printf("%d\n", a - b);
  return 0;
}

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

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)

int N;
int A[100];

int main() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", &A[i]);

  sort(A, A + N, greater<int>());
  int a = 0, b = 0;
  REP(i, N) {
    if (i % 2 == 0)
      a += A[i];
    else
      b += A[i];
  }

  printf("%d\n", a - b);
  return 0;
}
Problem p03434 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, x = 0, y = 0;
  cin >> a;
  int b[a];
  for (int i = 0; i < a; i++)
    cin >> b[i];
  sort(b, b + a);
  for (int i = 1; i <= a; i--) {
    if (i % 2)
      x += b[a - i];
    else
      y += b[a - i];
  }
  cout << x - y << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, x = 0, y = 0;
  cin >> a;
  int b[a];
  for (int i = 0; i < a; i++)
    cin >> b[i];
  sort(b, b + a);
  for (int i = 1; i <= a; i++) {
    if (i % 2)
      x += b[a - i];
    else
      y += b[a - i];
  }
  cout << x - y << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int Alice = 0, Bob = 0;
  for (int k = 0; k < (a.size() + 1) / 2; k++) {
    Alice += a.at(2 * k);
    Bob += a.at(2 * k + 1);
  }
  cout << Alice - Bob << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int Alice = 0, Bob = 0;
  for (int k = 0; k < a.size(); k++) {
    if (k % 2 == 0) {
      Alice += a.at(k);
    } else {
      Bob += a.at(k);
    }
  }
  cout << Alice - Bob << endl;
}
Problem p03434 (C++)

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

int main() {
  int n, b, c;
  b = 0;
  c = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      b = b + a.at(i);
    } else {
      c = c + a.at(i + 1);
    }
  }
  cout << b - c << endl;
}


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

int main() {
  int n, b, c;
  b = 0;
  c = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      b = b + a.at(i);
    } else {
      c = c + a.at(i);
    }
  }
  cout << b - c << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  int a[N];
  cin >> N;
  int i;
  for (i = 0; i < N; ++i) {
    cin >> a[i];
  }
  int Al = 0;
  int Bo = 0;
  int memo;
  for (int p = 0; p < N; ++p) {
    int max = 0;
    for (i = 0; i < N; ++i) {
      if (max < a[i]) {
        max = a[i];
        memo = i;
      }
    }
    a[memo] = 0;
    if (p % 2 == 0) {
      Al = Al + max;
    } else {
      Bo = Bo + max;
    }
  }
  cout << Al - Bo << endl;
  return 0;
}


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

int main() {
  int N;
  int a[110];
  cin >> N;
  int i;
  for (i = 0; i < N; ++i) {
    cin >> a[i];
  }
  int Al = 0;
  int Bo = 0;
  int memo;
  for (int p = 0; p < N; ++p) {
    int max = 0;
    for (i = 0; i < N; ++i) {
      if (max < a[i]) {
        max = a[i];
        memo = i;
      }
    }
    a[memo] = 0;
    if (p % 2 == 0) {
      Al = Al + max;
    } else {
      Bo = Bo + max;
    }
  }
  cout << Al - Bo << endl;
  return 0;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int sum_a = 0;
  int sum_b = 0;
  sort(vec.end(), vec.begin());
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0)
      sum_a += vec.at(i);
    else
      sum_b += vec.at(i);
  }
  cout << sum_a - sum_b;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int sum_a = 0;
  int sum_b = 0;
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0)
      sum_a += vec.at(i);
    else
      sum_b += vec.at(i);
  }
  cout << sum_a - sum_b;
}
Problem p03434 (C++)

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

int main() {
  int N, Alice = 0, Bob = 0, Answer = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < N; i += 2) {
    Alice += a.at(i);
    Bob += a.at(i + 1);
  }
  Answer = Alice - Bob;
  cout << Answer << endl;
}

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

int main() {
  int N, Alice = 0, Bob = 0, Answer = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < N; i += 2) {
    Alice += a.at(i);
    if (i + 1 < N)
      Bob += a.at(i + 1);
  }
  Answer = Alice - Bob;
  cout << Answer << endl;
}
Problem p03434 (C++)

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

int main() {
  int N, Alice = 0, Bob = 0;
  cin >> N;
  vector<int> card(N);

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

  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N - 1; j++) {
      if (card.at(j) < card.at(j + 1)) {
        swap(card.at(j), card.at(j + 1));
      }
    }
  }

  for (int i = 0; i < N; i += 2) {
    Alice += card.at(i);
  }

  for (int i = 0; i < N; i += 2) {
    Bob += card.at(i + 1);
  }

  cout << Alice - Bob << endl;
}

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

int main() {
  int N, Alice = 0, Bob = 0;
  cin >> N;
  vector<int> card(N);

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

  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N - 1; j++) {
      if (card.at(j) < card.at(j + 1)) {
        swap(card.at(j), card.at(j + 1));
      }
    }
  }

  for (int i = 0; i < N; i += 2) {
    Alice += card.at(i);
  }

  for (int i = 1; i < N; i += 2) {
    Bob += card.at(i);
  }

  cout << Alice - Bob << endl;
}
Problem p03434 (C++)

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

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
#define FOR(i, n, m) for (ll i = n; i < (ll)m; i++)
#define FORr(i, n, m) for (ll i = n; i > (ll)m; i--)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define cinv(v, n, m) FOR(i, n, m) cin >> v.at(i)
#define coutv(v, n, m) FOR(i, n, m) cout << v.at(i) << " "
#define cout(n) cout << fixed << setprecision(n)
int main() {
  ll N;
  cin >> N;
  vector<ll> v;
  cinv(v, 0, N);
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  ll Al = 0, Bo = 0;
  FOR(i, 0, N) {
    if (i % 2 == 0)
      Al += v[i];
    else
      Bo += v[i];
  }
  cout << Al - Bo << endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
#define FOR(i, n, m) for (ll i = n; i < (ll)m; i++)
#define FORr(i, n, m) for (ll i = n; i > (ll)m; i--)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define cinv(v, n, m) FOR(i, n, m) cin >> v.at(i)
#define coutv(v, n, m) FOR(i, n, m) cout << v.at(i) << " "
#define cout(n) cout << fixed << setprecision(n)
int main() {
  ll N;
  cin >> N;
  vector<ll> v(N);
  cinv(v, 0, N);
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  ll Al = 0, Bo = 0;
  FOR(i, 0, N) {
    if (i % 2 == 0)
      Al += v[i];
    else
      Bo += v[i];
  }
  cout << Al - Bo << endl;
}
Problem p03434 (C++)

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

int main() {
  vector<int> a;
  int N;
  int sum1 = 0;
  int sum2 = 0;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  for (int i = 0; i < N; ++i) {
    if (i % 2 == 0) {
      sum1 += a.at(i);
    } else {
      sum2 += a.at(i);
    }
  }
  cout << sum1 - sum2 << endl;
}

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

int main() {
  vector<int> a(100);
  int N;
  int sum1 = 0;
  int sum2 = 0;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  for (int i = 0; i < N; ++i) {
    if (i % 2 == 0) {
      sum1 += a.at(i);
    } else {
      sum2 += a.at(i);
    }
  }
  cout << sum1 - sum2 << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  int a[110];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N, greater<int>());
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; 1 < N; i++) {
    if (i % 2 == 0) {
      Alice += a[i];
    } else {
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
}


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

int main() {
  int N;
  int a[110];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N, greater<int>());
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      Alice += a[i];
    } else {
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
}
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N - 1);

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < N; i += 2) {
    Alice += a.at(i);
  }
  for (int i = 1; i < N; i += 2) {
    Bob += a.at(i);
  }
  int ans = Alice - Bob;

  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < N; i += 2) {
    Alice += a.at(i);
  }
  for (int i = 1; i < N; i += 2) {
    Bob += a.at(i);
  }
  int ans = Alice - Bob;

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

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

int main() {
  int N;
  int a[N]; // 最大 100 個ですが余裕をもたせます
  cin >> N;
  for (int i = 0; i < N; ++i)
    cin >> a[i];

  sort(a, a + N, greater<int>()); // a[0:N] を大きい順にソート
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < N; ++i) {
    if (i % 2 == 0) { // Alice のターン
      Alice += a[i];
    } else { // Bob のターン
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
}

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

int main() {
  int N;
  int a[110]; // 最大 100 個ですが余裕をもたせます
  cin >> N;
  for (int i = 0; i < N; ++i)
    cin >> a[i];

  sort(a, a + N, greater<int>()); // a[0:N] を大きい順にソート
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < N; ++i) {
    if (i % 2 == 0) { // Alice のターン
      Alice += a[i];
    } else { // Bob のターン
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
}
Problem p03434 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
nums = [int(i) for i in input().split()]

nums.sort_values(reverse=True)
print(sum(nums[0::2]) - sum(nums[1::2]))


Fixed submission:
n = int(input())
nums = [int(i) for i in input().split()]

nums.sort(reverse=True)
print(sum(nums[0::2]) - sum(nums[1::2]))
Problem p03434 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> vect;
  for (int i = 0; i < N; i++) {
    cin >> vect.at(i);
  }
  sort(vect.begin(), vect.end());
  reverse(vect.begin(), vect.end());
  int diff = 0;
  for (int i = 0; i < N; i++) {
    diff += (1 - 2 * (i % 2)) * vect.at(i);
  }
  cout << diff << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vect(N);
  for (int i = 0; i < N; i++) {
    cin >> vect.at(i);
  }
  sort(vect.begin(), vect.end());
  reverse(vect.begin(), vect.end());
  int diff = 0;
  for (int i = 0; i < N; i++) {
    diff += (1 - 2 * (i % 2)) * vect.at(i);
  }
  cout << diff << endl;
}
Problem p03434 (C++)

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

int main() {
  int N, alice, bob;
  cin >> N;
  vector<int> cards(N);
  for (int i = 0; i < N; i++)
    cin >> cards.at(i);
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  for (int i = 0; i < N; i += 2) {
    alice += cards.at(i);
    bob += cards.at(i + 1);
  }
  cout << alice - bob << endl;
}


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

int main() {
  int N, alice, bob;
  cin >> N;
  vector<int> cards(N + 10);
  for (int i = 0; i < N; i++)
    cin >> cards.at(i);
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  for (int i = 0; i < N; i += 2) {
    alice += cards.at(i);
    bob += cards.at(i + 1);
  }
  cout << alice - bob << endl;
}
Problem p03435 (Python)

Buggy submission (status: Time Limit Exceeded):
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

for a1 in range(max(c[0][0], c[0][1], c[0][2]) + 1):
    for a2 in range(max(c[1][0], c[1][1], c[1][2]) + 1):
        for a3 in range(max(c[2][0], c[2][1], c[2][2]) + 1):
            for b1 in range(max(c[0][0], c[1][0], c[2][0]) + 1):
                for b2 in range(max(c[0][1], c[1][1], c[2][1]) + 1):
                    for b3 in range(max(c[0][2], c[1][2], c[2][2]) + 1):
                        if (
                            a1 + b1 == c[0][0]
                            and a1 + b2 == c[0][1]
                            and a1 + b3 == c[0][2]
                            and a2 + b1 == c[1][0]
                            and a2 + b2 == c[1][1]
                            and a2 + b3 == c[1][2]
                            and a3 + b1 == c[2][0]
                            and a3 + b2 == c[2][1]
                            and a3 + b3 == c[2][2]
                        ):
                            print("Yes")
                            exit()
print("No")


Fixed submission:
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

x = [0] * 3
y = [0] * 3

for i in range(3):
    y[i] = c[0][i] - x[0]
for i in range(3):
    x[i] = c[i][0] - y[0]

for i in range(3):
    for j in range(3):
        if x[i] + y[j] != c[i][j]:
            print("No")
            exit()

print("Yes")
Problem p03435 (Python)

Buggy submission (status: Runtime Error):
import numpy as np

grid = np.array([])
for _ in range(3):
    list1 = list(map(int, input().split()))
    grid = np.append(grid, list1)

grid = grid.reshape(3, 3)
grid2 = np.vstack((grid[1:3, :], grid[0, :]))
judge = grid - grid2
judge = judge.transpose()
judge2 = np.copy(judge)
judge2 = np.vstack((judge2[1:3, :], judge2[0, :]))
new_judge = judge - judge2

if new_judge == np.zeros(3, 3):
    print("Yes")
else:
    print("No")


Fixed submission:
import numpy as np

grid = np.array([])
for _ in range(3):
    list1 = list(map(int, input().split()))
    grid = np.append(grid, list1)

grid = grid.reshape(3, 3)
grid2 = np.vstack((grid[1:3, :], grid[0, :]))
judge = grid - grid2
judge = judge.transpose()
judge2 = np.copy(judge)
judge2 = np.vstack((judge2[1:3, :], judge2[0, :]))
new_judge = judge - judge2

if np.allclose(new_judge, np.zeros_like(new_judge)):
    print("Yes")
else:
    print("No")
Problem p03435 (Python)

Buggy submission (status: Runtime Error):
c = [list(map(int, input().split())) for _ in range(3)]
try:
    assert (sum(c[2]) - sum(c[1])) % 3 == 0
    assert (sum(c[1]) - sum(c[0])) % 3 == 0
    assert (sum([c[2] for line in c]) - sum([c[1] for line in c])) % 3 == 0
    assert (sum([c[1] for line in c]) - sum([c[0] for line in c])) % 3 == 0
    print("Yes")
except AssertionError:
    print("No")


Fixed submission:
c = [list(map(int, input().split())) for _ in range(3)]
try:
    assert (sum(c[2]) - sum(c[1])) % 3 == 0
    assert (sum(c[1]) - sum(c[0])) % 3 == 0
    assert (sum([line[2] for line in c]) - sum([line[1] for line in c])) % 3 == 0
    assert (sum([line[1] for line in c]) - sum([line[0] for line in c])) % 3 == 0
    print("Yes")
except AssertionError:
    print("No")
Problem p03435 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long c[3][3];
  long long a[3] = {0};
  long long b[3] = {0};
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> c[i][j];
    }
  }
  b[1] = c[1][1];
  b[2] = c[1][2];
  b[3] = c[1][3];
  a[1] = 0;
  a[2] = c[2][2] - b[2];
  a[3] = c[3][3] - b[3];
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      if (c[i][j] != a[i] + b[j]) {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long c[4][4];
  long long a[4];
  long long b[4];
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> c[i][j];
    }
  }
  b[1] = c[1][1];
  b[2] = c[1][2];
  b[3] = c[1][3];
  a[1] = 0;
  a[2] = c[2][2] - b[2];
  a[3] = c[3][3] - b[3];
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      if (c[i][j] != a[i] + b[j]) {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}
Problem p03435 (C++)

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

using namespace std;
int a[4][4];
int check(int i) {
  int b1 = a[0][0] - i, b2 = a[0][1] - i, b3 = a[0][2] - i;
  int a2 = a[1][0] - b1, a3 = a[2][0] - b1;
  if (a2 + b2 == a[1][1] && a2 + b3 == a[1][2] && a3 + b2 == a[2][1] &&
      a3 + b3 == a[2][2]) {
    return 1;
  }
  return 0;
}
int main() {

  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      cin >> a[i][j];
  for (int i = -200; i <= 200; i++) {
    if (check(i))
      return puts("Yes");
  }
  puts("No");
  return 0;
}


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

using namespace std;
int a[4][4];
int check(int i) {
  int b1 = a[0][0] - i, b2 = a[0][1] - i, b3 = a[0][2] - i;
  int a2 = a[1][0] - b1, a3 = a[2][0] - b1;
  if (a2 + b2 == a[1][1] && a2 + b3 == a[1][2] && a3 + b2 == a[2][1] &&
      a3 + b3 == a[2][2]) {
    return 1;
  }
  return 0;
}
int main() {

  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      cin >> a[i][j];
  for (int i = -200; i <= 200; i++) {
    if (check(i)) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  puts("No");
  return 0;
}
Problem p03435 (C++)

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

int main() {
  vector<vector<int>> c(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);
    }
  }

  int sum = 0;
  int ref = 0;

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (i == j) {
        sum += c.at(i).at(j);
        ref += c.at(i).at(j);
      } else
        sum += c.at(i).at(j);
    }
  }

  if (sum % ref == 0)
    cout << "Yes";
  else
    cout << "No";
}


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

int main() {
  vector<vector<int>> c(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);
    }
  }

  int sum = 0;
  int ref = 0;

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (i == j) {
        sum += c.at(i).at(j);
        ref += c.at(i).at(j);
      } else
        sum += c.at(i).at(j);
    }
  }

  if (sum == 0 && ref == 0)
    cout << "Yes";
  else if (sum % ref == 0)
    cout << "Yes";
  else
    cout << "No";
}
Problem p03435 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>> c(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);
    }
  }
  int x = c.at(2).at(1) - c.at(1).at(1);
  int y = c.at(3).at(1) - c.at(2).at(1);
  int p = c.at(2).at(2) - c.at(1).at(2);
  int q = c.at(3).at(2) - c.at(2).at(2);
  int s = c.at(2).at(3) - c.at(1).at(3);
  int t = c.at(3).at(3) - c.at(2).at(3);
  if (p == x && s == x && q == y && t == y) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>> c(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);
    }
  }
  int x = c.at(1).at(0) - c.at(0).at(0);
  int y = c.at(2).at(0) - c.at(1).at(0);
  int p = c.at(1).at(1) - c.at(0).at(1);
  int q = c.at(2).at(1) - c.at(1).at(1);
  int s = c.at(1).at(2) - c.at(0).at(2);
  int t = c.at(2).at(2) - c.at(1).at(2);
  if (p == x && s == x && q == y && t == y) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}