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

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

#define MOD 998244353
#define MAX_P 1100005
Int fact[MAX_P], inv[MAX_P], finv[MAX_P];

void init(Int mod) {
  fact[0] = 1;
  for (Int i = 1; i < MAX_P; i++)
    fact[i] = (fact[i - 1] * i) % mod;

  inv[1] = 1;
  for (Int i = 2; i < MAX_P; i++)
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;

  finv[0] = 1;
  for (Int i = 1; i < MAX_P; i++)
    finv[i] = finv[i - 1] * inv[i] % mod;
}

// only for prime mod
Int mod_comb3(Int n, Int k, Int mod) {
  if (k < 0 || k > n)
    return 0;
  return fact[n] * finv[k] % mod * finv[n - k] % mod;
}

Int calc(Int n, Int k, Int i) {
  Int j = k - i;
  Int res = 0;
  res += mod_comb3(k, i, MOD);
  res += MOD - mod_comb3(k, j - (i - n + 1), MOD);
  // cout<<n<<" "<<k<<" "<<i<<" "<<j<<":"<<res<<endl;
  return res % MOD;
}

// INSERT ABOVE HERE
signed main() {
  init(MOD);
  Int n, k;
  cin >> n >> k;
  Int ans = 0;
  for (Int i = k; i >= n; i--) {
    Int j = k - i;
    if (i - j < 0)
      continue;
    if (i == j) {
      assert(i == n);
      for (Int x = 0; x <= i - n; x++) {
        ans += calc(n, 2 * n, i - x) * mod_comb3(k - n * 2, x, MOD) % MOD;
        ans %= MOD;
      }
    } else {
      ans += calc(n, k, i);
    }
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


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

#define MOD 998244353
#define MAX_P 1100005
Int fact[MAX_P], inv[MAX_P], finv[MAX_P];

void init(Int mod) {
  fact[0] = 1;
  for (Int i = 1; i < MAX_P; i++)
    fact[i] = (fact[i - 1] * i) % mod;

  inv[1] = 1;
  for (Int i = 2; i < MAX_P; i++)
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;

  finv[0] = 1;
  for (Int i = 1; i < MAX_P; i++)
    finv[i] = finv[i - 1] * inv[i] % mod;
}

// only for prime mod
Int mod_comb3(Int n, Int k, Int mod) {
  if (k < 0 || k > n)
    return 0;
  return fact[n] * finv[k] % mod * finv[n - k] % mod;
}

Int calc(Int n, Int k, Int i) {
  Int j = k - i;
  Int res = 0;
  res += mod_comb3(k, i, MOD);
  res += MOD - mod_comb3(k, j - (i - n + 1), MOD);
  // cout<<n<<" "<<k<<" "<<i<<" "<<j<<":"<<res<<endl;
  return res % MOD;
}

// INSERT ABOVE HERE
signed main() {
  init(MOD);
  Int n, k;
  cin >> n >> k;
  Int ans = 0;
  for (Int i = k; i >= n; i--) {
    Int j = k - i;
    if (i - j < 0)
      continue;
    ans += calc(n, k - (i == j), i);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p03431 (C++)

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

const int maxn = 500100;
const int base = 998244353;

using namespace std;

ll fac[maxn], inv[maxn], n, k, res;

ll pow(ll n, int k) {
  if (k == 0)
    return 1;
  if (k == 1)
    return n;
  ll mid = pow(n, k / 2);
  mid = (mid * mid) % base;
  if (k % 2 == 0)
    return mid;
  return (mid * n) % base;
}

ll C(int n, int k) {
  // cout<<n<<" "<<k<<" "<<fac[n]<<" "<<inv[k]<<" "<<inv[n-k]<<endl;
  if (k > n)
    return 0;
  if (k == n)
    return 1;
  // cout<<n<<" "<<k<<" "<<fac[n]<<" "<<inv[k]<<" "<<inv[n-k]<<" "<<((fac[n] *
  // inv[k]) % base * inv[n-k]) % base<<endl;
  return ((fac[n] * inv[k]) % base * inv[n - k]) % base;
}

int main() {
  // freopen("in.txt","r",stdin);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  fac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i <= maxn; i++) {
    fac[i] = (fac[i - 1] * i) % base;
    inv[i] = pow(fac[i], base - 2) % base;
  }
  cin >> n >> k;
  if (k < n) {
    cout << 0 << endl;
    return 1;
  }
  for (int R = 0; R <= k; R++) {
    int B = k - R;
    if (R == B)
      res = (res + C(R + B - 1, R) - C(R + B - 1, R + B - n + 1)) % base;
    else if (R > B)
      res = (res + C(R + B, R) - C(R + B, 2 * R - n + 1)) % base;
  }
  cout << res << endl;
}


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

const int maxn = 500100;
const int base = 998244353;

using namespace std;

ll fac[maxn], inv[maxn], n, k, res;

ll pow(ll n, int k) {
  if (k == 0)
    return 1;
  if (k == 1)
    return n;
  ll mid = pow(n, k / 2);
  mid = (mid * mid) % base;
  if (k % 2 == 0)
    return mid;
  return (mid * n) % base;
}

ll C(int n, int k) {
  // cout<<n<<" "<<k<<" "<<fac[n]<<" "<<inv[k]<<" "<<inv[n-k]<<endl;
  if (k > n)
    return 0;
  if (k == n)
    return 1;
  // cout<<n<<" "<<k<<" "<<fac[n]<<" "<<inv[k]<<" "<<inv[n-k]<<" "<<((fac[n] *
  // inv[k]) % base * inv[n-k]) % base<<endl;
  return ((fac[n] * inv[k]) % base * inv[n - k]) % base;
}

int main() {
  // freopen("in.txt","r",stdin);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  fac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i <= maxn; i++) {
    fac[i] = (fac[i - 1] * i) % base;
    inv[i] = pow(fac[i], base - 2) % base;
  }
  cin >> n >> k;
  if (k < n) {
    cout << 0 << endl;
    return 0;
  }
  for (int R = 0; R <= k; R++) {
    int B = k - R;
    if (R == B)
      res = (res + C(R + B - 1, R) - C(R + B - 1, R + B - n + 1)) % base;
    else if (R > B)
      res = (res + C(R + B, R) - C(R + B, 2 * R - n + 1)) % base;
  }
  cout << res << endl;
}
Problem p03431 (C++)

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

typedef long long LL;
typedef unsigned long long ULL;

#define debug printf("fuck %d\n", __LINE__);

inline LL read() {
  LL res = 0, bo = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      bo = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    res = (res << 1) + (res << 3) + ch - '0';
    ch = getchar();
  }
  return bo * res;
}

template <typename T> void read(T &x) { x = read(); }
template <typename T, typename... Argv> void read(T &a, Argv &...argv) {
  read(a);
  read(argv...);
}

const int N = 6e5 + 10, p = 998244353;
int fac[N], inv[N];

int ksm(int x, int y) {
  int res = 1;
  for (; y; y >>= 1, x = 1LL * x * x % p)
    if (y & 1)
      res = 1LL * res * x % p;
  return res;
}

void init(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i)
    fac[i] = 1LL * fac[i - 1] * i % p;
  inv[n] = ksm(fac[n], p - 2);
  for (int i = n - 1; ~i; --i)
    inv[i] = 1LL * inv[i + 1] * (i + 1) % p;
}

int C(int n, int m) {
  return m > n ? 0 : 1LL * fac[n] * inv[m] % p * inv[n - m] % p;
}

int main() {
  int n = read(), k = read();
  init(N - 1);
  int ans = 0;
  for (int i = 1; i <= k; ++i) {
    int r = i, b = k - i;
    // std::cout << r << ' ' << b << ' ' << C(k, r) << ' ' << fac[i] << ' ' <<
    // inv[i] << ' ' << fac[i] * inv[i] % p << std::endl;
    if (r < b)
      continue;
    if (r - b >= n)
      (ans += C(k, r)) %= p;
    else
      (ans += C(k, r) - C(k, (r << 1) - n + 1)) %= p;
  }
  std::cout << ans << std::endl;
  return 0;
}

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

typedef long long LL;
typedef unsigned long long ULL;

#define debug printf("fuck %d\n", __LINE__);

inline LL read() {
  LL res = 0, bo = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      bo = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    res = (res << 1) + (res << 3) + ch - '0';
    ch = getchar();
  }
  return bo * res;
}

template <typename T> void read(T &x) { x = read(); }
template <typename T, typename... Argv> void read(T &a, Argv &...argv) {
  read(a);
  read(argv...);
}

const int N = 6e5 + 10, p = 998244353;
int fac[N], inv[N];

int ksm(int x, int y) {
  int res = 1;
  for (; y; y >>= 1, x = 1LL * x * x % p)
    if (y & 1)
      res = 1LL * res * x % p;
  return res;
}

void init(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i)
    fac[i] = 1LL * fac[i - 1] * i % p;
  inv[n] = ksm(fac[n], p - 2);
  for (int i = n - 1; ~i; --i)
    inv[i] = 1LL * inv[i + 1] * (i + 1) % p;
}

int C(int n, int m) {
  return m > n ? 0 : 1LL * fac[n] * inv[m] % p * inv[n - m] % p;
}

int main() {
  int n = read(), k = read();
  init(N - 1);
  int ans = 0;
  for (int i = n; i <= k; ++i) {
    (ans += C(k - 1, i - 1)) %= p;
  }
  std::cout << ans << std::endl;
  return 0;
}
Problem p03431 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int read() {
  char ch = getchar();
  int w = 1, c = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      w = -1;
  for (; isdigit(ch); ch = getchar())
    c = (c << 3) + (c << 1) + (ch ^ 48);
  return w * c;
}
const int mod = 998244353, M = 1e6 + 10;
LL f[M], inv_f[M], ans;
int n, m;
LL fast(LL x, LL p) {
  LL res = 1;
  for (; p; p >>= 1, x = x * x % mod)
    if (p & 1)
      res = res * x % mod;
  return res;
}
LL C(int n, int m) {
  if (m > n)
    return 0;
  return f[n] * inv_f[m] % mod * inv_f[n - m] % mod;
}
LL calc(int x, int y, int t) {
  //	cout<<x<<" "<<y<<" "<<t<<"\n";
  //	cout<<C(x+y,x)<<" "<<C(x+y,x+t)<<"\n";
  return C(x + y, y) - C(x + y, x + t);
}
int main() {
  n = read();
  m = read();
  f[0] = 1;
  for (int i = 1; i <= m + n; i++) {
    f[i] = f[i - 1] * i % mod;
  }
  inv_f[m + n] = fast(f[m + n], mod - 2);
  for (int i = m + n; i; i--)
    inv_f[i - 1] = inv_f[i] * i % mod;

  //	cout<<C(4,4)<<" "<<f[4]<<" "<<inv_f[2]<<" "<<"\n";
  //
  //	cout<<8*inv_f[2]%mod<<"\n";

  for (int i = 0; i <= m; i++) {
    int R = i, B = m - i;
    if (R == B)
      ans = (ans + calc(R, B - 1, R - n + 1) + mod) % mod;
    if (R > B)
      ans = (ans + calc(R, B, R - n + 1) + mod) % mod;
  }
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int read() {
  char ch = getchar();
  int w = 1, c = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      w = -1;
  for (; isdigit(ch); ch = getchar())
    c = (c << 3) + (c << 1) + (ch ^ 48);
  return w * c;
}
const int mod = 998244353, M = 1e6 + 10;
LL f[M], inv_f[M], ans;
int n, m;
LL fast(LL x, LL p) {
  LL res = 1;
  for (; p; p >>= 1, x = x * x % mod)
    if (p & 1)
      res = res * x % mod;
  return res;
}
LL C(int n, int m) {
  if (m > n)
    return 0;
  return f[n] * inv_f[m] % mod * inv_f[n - m] % mod;
}
LL calc(int x, int y, int t) {
  //	cout<<x<<" "<<y<<" "<<t<<"\n";
  //	cout<<C(x+y,x)<<" "<<C(x+y,x+t)<<"\n";
  return C(x + y, y) - C(x + y, x + t);
}
int main() {
  n = read();
  m = read();
  if (m < n) {
    cout << 0 << "\n";
    return 0;
  }
  f[0] = 1;
  for (int i = 1; i <= m + n; i++) {
    f[i] = f[i - 1] * i % mod;
  }
  inv_f[m + n] = fast(f[m + n], mod - 2);
  for (int i = m + n; i; i--)
    inv_f[i - 1] = inv_f[i] * i % mod;

  //	cout<<C(4,4)<<" "<<f[4]<<" "<<inv_f[2]<<" "<<"\n";
  //
  //	cout<<8*inv_f[2]%mod<<"\n";

  for (int i = 0; i <= m; i++) {
    int R = i, B = m - i;
    if (R == B)
      ans = (ans + calc(R, B - 1, R - n + 1) + mod) % mod;
    if (R > B)
      ans = (ans + calc(R, B, R - n + 1) + mod) % mod;
  }
  cout << ans << "\n";
  return 0;
}
Problem p03431 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#define MOD 998244353
typedef long long ll;
inline ll quick_pow(ll a, int n) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
ll fact[500005], inv[500005];
inline ll C(int n, int m) { return fact[n] * inv[m] % MOD * inv[n - m] % MOD; }
int main() {
  // freopen("AGC021-E.in", "r", stdin);
  int n, k;
  scanf("%d%d", &n, &k);
  fact[0] = inv[0] = 1;
  for (int i = 1; i <= k; i++) {
    fact[i] = fact[i - 1] * i % MOD;
    inv[i] = quick_pow(fact[i], MOD - 2);
  }
  ll ans = 0;
  for (int r = n; r <= k; r++) {
    if (r < k - r)
      continue;
    (ans += C(k, r) - C(k, 2 * r - n + 1)) %= MOD;
    if (r + r == k)
      (ans += C(k - 1, n - 1) - C(k - 1, r)) %= MOD;
  }
  printf("%lld\n", (ans + MOD) % MOD);
  return 0;
}


Fixed submission:
#include <cstdio>
#define MOD 998244353
typedef long long ll;
inline ll quick_pow(ll a, int n) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
ll fact[500005], inv[500005];
inline ll C(int n, int m) {
  if (n < m || m < 0)
    return 0;
  return fact[n] * inv[m] % MOD * inv[n - m] % MOD;
}
int main() {
  // freopen("AGC021-E.in", "r", stdin);
  int n, k;
  scanf("%d%d", &n, &k);
  fact[0] = inv[0] = 1;
  for (int i = 1; i <= k; i++) {
    fact[i] = fact[i - 1] * i % MOD;
    inv[i] = quick_pow(fact[i], MOD - 2);
  }
  ll ans = 0;
  for (int r = n; r <= k; r++) {
    if (r < k - r)
      continue;
    (ans += C(k, r) - C(k, 2 * r - n + 1)) %= MOD;
    if (r + r == k)
      (ans += C(k - 1, n - 1) - C(k - 1, r)) %= MOD;
  }
  printf("%lld\n", (ans + MOD) % MOD);
  return 0;
}
Problem p03431 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
using namespace std;
const int mod = 998244353;
const int maxn = 1000000;
long long fir[maxn + 5], inv[maxn + 5], ans = 0;
long long C(int n, int m) {
  if (n < m)
    return 0;
  return fir[n] * inv[m] % mod * inv[n - m] % mod;
}
long long ksm(long long x, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1)
      ans = ans * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ans;
}
void pre() {
  fir[0] = fir[1] = 1;
  for (int i = 2; i <= maxn; i++)
    fir[i] = fir[i - 1] * i % mod;
  inv[maxn] = ksm(fir[maxn], mod - 2);
  for (int i = maxn - 1; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
}
int main() {
  pre();
  int n, k;
  scanf("%d%d", &n, &k);
  for (int R = 1; R <= k; R++) {
    int B = k - R;
    if (R < B)
      continue;
    if (R == B)
      B--;
    ans = (ans + C(R + B, R) - C(R + B, 2 * R - n + 1)) % mod;
  }
  ans = (ans % mod + mod) % mod;
  printf("%lld\n", ans);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
using namespace std;
const int mod = 998244353;
const int maxn = 1000000;
long long fir[maxn + 5], inv[maxn + 5], ans = 0;
long long C(int n, int m) {
  if (n < m)
    return 0;
  return fir[n] * inv[m] % mod * inv[n - m] % mod;
}
long long ksm(long long x, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1)
      ans = ans * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ans;
}
void pre() {
  fir[0] = fir[1] = 1;
  for (int i = 2; i <= maxn; i++)
    fir[i] = fir[i - 1] * i % mod;
  inv[maxn] = ksm(fir[maxn], mod - 2);
  for (int i = maxn - 1; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
}
int main() {
  pre();
  int n, k;
  scanf("%d%d", &n, &k);
  if (k < n) {
    puts("0");
    return 0;
  }
  for (int R = 1; R <= k; R++) {
    int B = k - R;
    if (R < B)
      continue;
    if (R == B)
      B--;
    ans = (ans + C(R + B, R) - C(R + B, 2 * R - n + 1)) % mod;
  }
  ans = (ans % mod + mod) % mod;
  printf("%lld\n", ans);
}
Problem p03431 (C++)

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

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  do
    x = x * 10 + ch - 48, ch = getchar();
  while (ch >= '0' && ch <= '9');
  return x * f;
}

typedef long long ll;
const int MAXN = 500001;
const int p = 998244353;

int n, k;
ll fac[MAXN], ifac[MAXN];

ll C(int n, int m) { return fac[n] * ifac[m] % p * ifac[n - m] % p; }

int main() {
  n = read(), k = read();
  if (k < n)
    return std::puts("0"), 0;
  fac[0] = 1;
  for (int i = 1; i <= k; i++)
    fac[i] = fac[i - 1] * i % p;
  ifac[0] = ifac[1] = 1;
  for (int i = 2; i <= k; i++)
    ifac[i] = (p - p / i) * ifac[p % i] % p;
  for (int i = 1; i <= k; i++)
    ifac[i] = ifac[i - 1] * ifac[i] % p;
  ll ans = 0;
  for (int r = (k - 1) / 2 + 1; r <= k; r++) {
    int b = k - r;
    if (r == b)
      b--;
    ans = ((ans + C(r + b, b)) % p + p - C(r + b, 2 * r - n + 1)) % p;
  }
  std::printf("%lld\n", ans);
  return 0;
}


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

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  do
    x = x * 10 + ch - 48, ch = getchar();
  while (ch >= '0' && ch <= '9');
  return x * f;
}

typedef long long ll;
const int MAXN = 500001;
const int p = 998244353;

int n, k;
ll fac[MAXN], ifac[MAXN];

ll C(int n, int m) {
  if (n < m)
    return 0;
  if (m < 0 || n < 0)
    return 0;
  return fac[n] * ifac[m] % p * ifac[n - m] % p;
}

int main() {
  n = read(), k = read();
  if (k < n)
    return std::puts("0"), 0;
  fac[0] = 1;
  for (int i = 1; i <= k; i++)
    fac[i] = fac[i - 1] * i % p;
  ifac[0] = ifac[1] = 1;
  for (int i = 2; i <= k; i++)
    ifac[i] = (p - p / i) * ifac[p % i] % p;
  for (int i = 1; i <= k; i++)
    ifac[i] = ifac[i - 1] * ifac[i] % p;
  ll ans = 0;
  for (int r = (k - 1) / 2 + 1; r <= k; r++) {
    int b = k - r;
    if (r == b)
      b--;
    ans = ((ans + C(r + b, b)) % p + p - C(r + b, 2 * r - n + 1)) % p;
  }
  std::printf("%lld\n", ans);
  return 0;
}
Problem p03433 (C++)

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

  int a = 0, b = 0;
  int ans = 0;

  cin >> a >> b;
  ans = a % b;
  if (ans <= b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {

  int a = 0, b = 0;
  int ans = 0;

  cin >> a >> b;
  ans = a % 500;
  if (ans <= b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

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

int main() {
  int a, b, c;
  string y, n;
  y = "Yes";
  n = "No";
  cin >> a >> b;
  c = a % 500;
  if (c == 0) {
    cout << y << endl;
    return 0;
  }
  if (c % b == 0) {
    cout << y << endl;
    return 0;
  }
  cout << n << endl;
}


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

int main() {
  int a, b, c;
  string y, n;
  y = "Yes";
  n = "No";
  cin >> a >> b;
  c = a % 500;
  if (c == 0) {
    cout << y << endl;
    return 0;
  }
  if (c <= b) {
    cout << y << endl;
    return 0;
  }
  cout << n << endl;
}
Problem p03433 (C++)

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

int main() {
  int n, a;
  cin >> n >> a;
  if (n % (a * 1) * 500 == 0 || n % 500 == 0 || n <= 500) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  int n, a;
  cin >> n >> a;
  if (a >= n % 500) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

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

int main() {

  int N, A;

  cin >> N >> A;

  if (N % A < A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {

  int N, A;

  cin >> N >> A;

  if (N % 500 <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

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

int main() {
  int n, a;
  cin >> n >> a;
  cout << (n + n % a <= a ? "Yes" : "No") << endl;
}

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

int main() {
  int n, a;
  cin >> n >> a;
  cout << (n % 500 <= a ? "Yes" : "No") << endl;
}
Problem p03433 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, a, b;
  cin >> n;
  cin >> a;
  b = n % a;
  if (b <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, a, b;
  cin >> n;
  cin >> a;
  b = n % 500;
  if (b <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n >> a;
  int s = n % a;

  if (s % a == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n >> a;
  if (n % 500 <= a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03433 (C++)

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

using namespace std;

int main() {
  int a, n;
  cin >> n >> a;
  if (n %= 500 <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int a, n;
  cin >> n >> a;
  if (n % 500 <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p03433 (C++)

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

int main() {
  int n, a;
  int count = 0;
  cin >> n >> a;
  count += n / a;
  count += n % a;
  if (count <= n) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  int n, a;
  int count = 0;
  cin >> n >> a;
  count += n % 500;
  // cout << count <<" "<< a << endl;
  if (count <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

Buggy submission (status: Runtime Error):
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
typedef long long ll; // int64
typedef unsigned long long ull;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int dy[4] = {0, 1, 0, -1};
//----------program from here----------

int main() {
  int N = 0, A = 0;
  cin >> N >> A;
  cout << (N % 500 % A ? "Yes" : "No") << endl;

  return 0;
}

Fixed submission:
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
typedef long long ll; // int64
typedef unsigned long long ull;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int dy[4] = {0, 1, 0, -1};
//----------program from here----------

int main() {
  int N = 0, A = 0;
  cin >> N >> A;
  cout << (N % 500 <= A ? "Yes" : "No") << endl;

  return 0;
}
Problem p03433 (C++)

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

int main() {
  int N, A;
  cin >> N >> A;
  N %= 500;
  if (A == 0 && N > 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << (N / A > 0 ? "No" : "Yes") << endl;
  return 0;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  N %= 500;
  if (A == 0) {
    cout << (N ? "No" : "Yes") << endl;
    return 0;
  }
  cout << (N / A > 0 ? "No" : "Yes") << endl;
  return 0;
}
Problem p03433 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int a, b;
  cin >> a;
  cin >> b;
  int c = a / (a % 500);
  if ((a - c) >= b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b;
  cin >> a;
  cin >> b;
  if (b >= (a % 500))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03433 (C++)

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

int main() {
  int N, A;
  cin >> N >> A;
  if (500 * N / A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
  int N, A;
  cin >> N >> A;
  if (N % 500 <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

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

int main() {
  int N;
  int A;

  cin >> N >> A;

  int i;
  i = N % 500;

  if (i / A <= 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  int N;
  int A;

  cin >> N >> A;

  int i;
  i = N % 500;

  if (i <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

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

int main() {
  int N, A;
  cin >> N >> A;
  if (N % 500 < A || N % A == A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
  int N, A;
  cin >> N >> A;
  if (N % 500 <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

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

int n, a;

int main(void) {
  scanf("%d", n);
  scanf("%d", a);

  if (n % 500 > a)
    printf("No");
  else
    printf("Yes");

  return 0;
}

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

int n, a;

int main(void) {
  scanf("%d", &n);
  scanf("%d", &a);

  if (n % 500 > a)
    printf("No");
  else
    printf("Yes");

  return 0;
}
Problem p03433 (C++)

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

int main() {
  int A, B;
  cin >> A >> B;

  if (A % B) {
    cout << A + B << endl;
  }
}

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

int main() {
  int N, A;
  cin >> N >> A;
  if (N % 500 > A) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}
Problem p03433 (C++)

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

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

  while (N >= 500) {
    N == N - 500;
  }
  if (N <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

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

  if ((N % 500) <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

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

int main() {
  unsigned int N, A, T;
  cin >> N >> A;
  T = N % 500;
  T %= A;
  cout << (T == 0 ? "Yes" : "No") << endl;
  return 0;
}

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

int main() {
  unsigned int N, A, T;
  cin >> N >> A;
  T = N % 500;

  cout << (A >= T ? "Yes" : "No") << endl;
  return 0;
}
Problem p03433 (C++)

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

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

  if (a >= (n % a)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

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

  if (a >= (n % 500)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

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

int main() {

  int N, A;
  cin >> N >> A;

  if (N <= A)
    cout << "Yes" << endl;

  else if (N % A <= A)
    cout << "Yes" << endl;

  else
    cout << "No" << endl;
}

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

int main() {

  int N, A;
  cin >> N >> A;

  if (N <= A)
    cout << "Yes" << endl;

  else if (N % 500 <= A)
    cout << "Yes" << endl;

  else
    cout << "No" << endl;
}
Problem p03433 (C++)

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

int main() {
  int N, A;
  cin >> N >> A;
  int x = N % 500;

  if (x % A == 0) {
    cout << "Yes" << endl;
  }

  else {
    cout << "No" << endl;
  }
}

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

int main() {
  int N, A;
  cin >> N >> A;
  int x = N % 500;

  if (x <= A) {
    cout << "Yes" << endl;
  }

  else {
    cout << "No" << endl;
  }
}
Problem p03433 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = int(input())

ans = N % A

if A == 0:
    print("No")
    exit()
print("Yes" if ans <= A else "No")


Fixed submission:
N = int(input())
A = int(input())

print("Yes" if N % 500 <= A else "No")
Problem p03433 (C++)

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

int main() {
  int N, A, B = 0;
  cin >> N >> A;
  B = N % 500;
  if (A % B == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  int N, A, B = 0;
  cin >> N >> A;
  B = N % 500;
  if (A >= B) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, a;
  cin >> n;
  cin >> a;

  if (n % 2 && 0 == a) {
    cout << "No" << endl;
    return 0;
  }

  int sp = n % 500;
  if (sp > a) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 1;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, a;
  cin >> n;
  cin >> a;

  if (n % 2 && 0 == a) {
    cout << "No" << endl;
    return 0;
  }

  int sp = n % 500;
  if (sp > a) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}
Problem p03433 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

n = input()
a = input()

if n % 500 <= a:
    print("Yes")
else:
    print("No")


Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
a = int(input())

if n % 500 <= a:
    print("Yes")
else:
    print("No")
Problem p03433 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int N, A;
int main() {
  cin >> N >> A;
  if (N % 500 == 0) {
    cout << "Yes" << endl;
  } else if (N % A == 0) {
    cout << "Yes" << endl;
  } else if ((N - A) % 500 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int N, A;
int main() {
  cin >> N >> A;
  if (N % 500 <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

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

int main() {
  int N, A;
  cin >> N >> A;
  if (N % A <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  int N, A;
  cin >> N >> A;
  if (N % 500 <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03433 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, a;
  cin >> n >> a;
  if (n % a <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, a;
  cin >> n >> a;
  if (n % 500 <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p03434 (C++)

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

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


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

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

Buggy submission (status: Time Limit Exceeded):
// ConsoleApplication2.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  int alice = 0;
  int bob = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  sort(a.begin(), a.end(), greater<int>());

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

  cout << alice - bob << endl;

  return 0;
}


Fixed submission:
// ConsoleApplication2.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  int alice = 0;
  int bob = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  sort(a.begin(), a.end(), greater<int>());

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

  cout << alice - bob << endl;

  return 0;
}
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[i];
  sort(a.rbegin(), a.rend());
  int sum = 0;
  for (int i = 0; i < N; i--) {
    if (i % 2 == 0) {
      sum += a[i];
    } else
      sum -= a[i];
  }
  cout << sum;
}


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[i];
  sort(a.rbegin(), a.rend());
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      sum += a[i];
    } else
      sum -= a[i];
  }
  cout << sum;
}
Problem p03434 (C++)

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

int main() {
  int Alice = 0, Bob = 0, 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());

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

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

int main() {
  int Alice = 0, Bob = 0, 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());

  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 <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N;
  int A[N];
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  sort(A, A + N, greater<int>());
  int sum1 = 0;
  int sum2 = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      sum1 += A[i];

    } else {
      sum2 += A[i];
    }
  }

  cout << sum1 - sum2 << 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 sum1 = 0;
  int sum2 = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      sum1 += A[i];

    } else {
      sum2 += A[i];
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <queue>

using namespace std;

const int MAX_N = 100;

int N;
int A[MAX_N];

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

  int N;
  cin >> N;

  priority_queue<int> que;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    que.push(A[i]);
  }

  int alice = 0;
  int bob = 0;
  while (true) {
    int a = que.top();
    que.pop();
    alice += a;
    if (que.empty())
      break;
    int b = que.top();
    que.pop();
    bob += b;
  }
  cout << alice - bob << "\n";
  return 0;
}

Fixed submission:
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <queue>

using namespace std;

const int MAX_N = 100;

int N;
int A[MAX_N];

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

  int N;
  cin >> N;

  priority_queue<int> que;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    que.push(A[i]);
  }

  int alice = 0;
  int bob = 0;
  while (!que.empty()) {
    int a = que.top();
    que.pop();
    alice += a;
    if (que.empty())
      break;
    int b = que.top();
    que.pop();
    bob += b;
  }
  cout << alice - bob << "\n";
  return 0;
}
Problem p03434 (C++)

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

int main() {
  int N = 0, Al = 0, Bo = 0, x = 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) {
    Al += A.at(i);
    Bo += A.at(i + 1);
  }
  cout << Al - Bo << endl;
}


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

int main() {
  int N = 0, Al = 0, Bo = 0, x = 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) {
      Al += A.at(i);
    } else {
      Bo += A.at(i);
    }
  }
  cout << Al - Bo << endl;
}
Problem p03434 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
a.soat(reverse=True)
A = sum([i for i in a[::2]])
B = sum([j for j in a[1::2]])
print(A - B)


Fixed submission:
N = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
A = sum([i for i in a[::2]])
B = sum([j for j in a[1::2]])
print(A - B)
Problem p03434 (Python)

Buggy submission (status: Runtime Error):
_, *a = map(int, open(0).read().split())
a.sorted()
print(sum(a[-1::2]) - sum(a[-2::2]))


Fixed submission:
_, *a = map(int, open(0).read().split())
a.sort()
print(sum(a[-1::-2]) - sum(a[-2::-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);
  }

  int diff = 0, sumdiff = 0;

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

  for (int i = 0; i < n; i += 2) {
    diff = max(vec.at(i) - vec.at(i + 1), vec.at(i + 1) - vec.at(i));
    sumdiff += diff;
  }

  cout << sumdiff << 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);
  }

  int diff = 0, sumdiff = 0;

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

  for (int i = 0; i < n - 1; i += 2) {
    diff = max(vec.at(n - 1 - i) - vec.at(n - 1 - (i + 1)),
               vec.at(n - 1 - (i + 1)) - vec.at(n - 1 - i));
    sumdiff += diff;
    //    cout << sumdiff << endl;
  }

  if (n % 2 == 1) {
    diff = vec.at(0);
    sumdiff += diff;
  }

  cout << sumdiff << 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;
  return 0;
}


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;
  return 0;
}
Problem p03434 (C++)

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

int main() {
  int n, a, b;
  a = 0, b = 0;
  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());

  for (int i = 0; i < n; i += 2) {
    a += vect.at(i);
    b += vect.at(i + 1);
  }

  cout << a - b << endl;
}


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

int main() {
  int n, a, b;
  a = 0, b = 0;
  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());

  for (int i = 0; i < n; i += 2) {
    a += vect.at(i);
  }
  for (int i = 1; i < n; i += 2) {
    b += vect.at(i);
  }

  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.end(), a.begin());
  int A = 0, B = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0)
      A += a.at(i);
    else
      B += a.at(i);
  }
  cout << A - B << endl;
  return 0;
}

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 A = 0, B = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0)
      A += a.at(i);
    else
      B += a.at(i);
  }
  cout << A - B << endl;
  return 0;
}
Problem p03434 (C++)

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

int main() {
  int n;
  int a[100];
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", n + i);
  }
  std::sort(a, a + n, std::greater<int>());
  int b = 0, c = 0;
  for (int i = 0; i < n; i += 2) {
    b += a[i];
  }
  for (int i = 1; i < n; i += 2) {
    c += a[i];
  }
  printf("%d\n", b - c);
  return 0;
}

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

int main() {
  int n;
  int a[100];
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  std::sort(a, a + n, std::greater<int>());
  int b = 0, c = 0;
  for (int i = 0; i < n; i += 2) {
    b += a[i];
  }
  for (int i = 1; i < n; i += 2) {
    c += a[i];
  }
  printf("%d\n", b - c);
  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> num(N);
  for (int i = 0; i < N; i++) {
    cin >> num.at(i);
  }
  sort(num.begin(), num.end());
  reverse(num.begin(), num.end());
  int A = 0, B = 0;
  for (int i = 0; i < N; i += 2) {
    A = A + num.at(i);
    B = B + num.at(i + 1);
  }
  cout << A - B << endl;
  return 0;
}


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

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

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

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

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

int main() {
  int n;
  cin >> n;
  int s = 0;
  vector<int> a(n + 1);
  rep(i, n) { cin >> a.at(i); }
  sort(a.begin(), a.end(), greater<int>());
  for (int i = 0; i < n; i += 2) {
    s += a.at(i);
    s -= a.at(i + 1);
  }
  cout << s << 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);
  }

  bool check = true;
  bool changed = false;
  int temp1;
  int temp2;

  while (check) {
    changed = false;
    for (int i = 0; i < N - 1; i++) {
      if (A.at(i) < A.at(i + 1)) {
        temp1 = A.at(i);
        temp2 = A.at(i + 1);
        A.at(i) = temp2;
        A.at(i + 1) = temp1;
        changed = true;
      }
    }

    if (changed = false) {
      check = false;
    }
  }

  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);
  }

  bool check = true;
  bool changed = false;
  int temp1;
  int temp2;

  while (check) {
    changed = false;
    for (int i = 0; i < N - 1; i++) {
      if (A.at(i) < A.at(i + 1)) {
        temp1 = A.at(i);
        temp2 = A.at(i + 1);
        A.at(i) = temp2;
        A.at(i + 1) = temp1;
        changed = true;
      }
    }

    if (changed == false) {
      check = false;
    }
  }

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

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

int N, A = 0, B = 0;
vector<int> a(100, 0);

int main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> a[i];
  for (int i = 0; i < N; i++) {
    A += *max_element(a.begin(), a.end());
    a.erase(max_element(a.begin(), a.end()));
    B += *max_element(a.begin(), a.end());
    a.erase(max_element(a.begin(), a.end()));
  }
  cout << A - B << endl;
  return 0;
}


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

int N, A = 0, B = 0;
vector<int> a(200, 0);

int main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> a[i];
  for (int i = 0; i < N; i++) {
    A += *max_element(a.begin(), a.end());
    a.erase(max_element(a.begin(), a.end()));
    B += *max_element(a.begin(), a.end());
    a.erase(max_element(a.begin(), a.end()));
  }
  cout << A - B << endl;
  return 0;
}
Problem p03434 (C++)

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

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

  const int NMAX = 50;
  vector<int> a(NMAX);

  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;
}