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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

ll N, K;
ll a[100010], b[100010];
int main() {
  cin >> N >> K;
  ll maxA = 0;
  for (ll i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
    maxA = max(maxA, a[i]);
  }
  ll maxBit = 0;
  for (ll i = 0; (1ll << i) <= maxA; i++) {
    if ((1ll << i) & maxA)
      maxBit = i;
  }
  for (ll i = 0; (1ll < i) <= K; i++) {
    if ((1ll << i) & K)
      maxBit = max(maxBit, i);
  }
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    bool f = true;
    for (ll bit = 0; bit <= maxBit; bit++) {
      if (((1ll << bit) & K) == 0 && ((1ll << bit) & a[i]) != 0) {
        f = false;
        break;
      }
    }
    if (f)
      ans += b[i];
  }
  for (ll bit = maxBit; bit >= 0; bit--) {
    if (((1ll << bit) & K) == 0)
      continue;
    ll sum = 0;
    for (ll i = 0; i < N; i++) {
      if ((1ll << bit) & a[i])
        continue;
      bool f = true;
      for (ll j = maxBit; j > bit; j--) {
        if (((1ll << j) & K) == 0 && ((1ll << j) & a[i]) != 0) {
          f = false;
          break;
        }
      }
      if (f)
        sum += b[i];
    }
    ans = max(sum, ans);
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

ll N, K;
ll a[100010], b[100010];
int main() {
  cin >> N >> K;
  ll maxA = 0;
  for (ll i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
    maxA = max(maxA, a[i]);
  }
  ll maxBit = 0;
  for (ll i = 0; (1ll << i) <= maxA; i++) {
    if ((1ll << i) & maxA)
      maxBit = i;
  }
  for (ll i = 0; (1ll << i) <= K; i++) {
    if ((1ll << i) & K)
      maxBit = max(maxBit, i);
  }
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    bool f = true;
    for (ll bit = 0; bit <= maxBit; bit++) {
      if (((1ll << bit) & K) == 0 && ((1ll << bit) & a[i]) != 0) {
        f = false;
        break;
      }
    }
    if (f)
      ans += b[i];
  }
  for (ll bit = maxBit; bit >= 0; bit--) {
    if (((1ll << bit) & K) == 0)
      continue;
    ll sum = 0;
    for (ll i = 0; i < N; i++) {
      if ((1ll << bit) & a[i])
        continue;
      bool f = true;
      for (ll j = maxBit; j > bit; j--) {
        if (((1ll << j) & K) == 0 && ((1ll << j) & a[i]) != 0) {
          f = false;
          break;
        }
      }
      if (f)
        sum += b[i];
    }
    ans = max(sum, ans);
  }
  cout << ans;
  return 0;
}
Problem p03584 (C++)

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi 1
#define LL long long
#define ULL unsigned long long
#define LD long double

using namespace std;

#define MAX_N 10005

LL N, K;
LL A[MAX_N], B[MAX_N];

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

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

  LL ans = 0;
  const LL MAX = 31;
  for (int i = 0; i < MAX; i++) {
    if (!((K >> i) & 1)) {
      continue;
    }
    LL mask = pow(2, MAX) - 1;
    LL mask2 = pow(2, i) - 1;
    mask <<= (i + 1);
    LL tmp = 0;
    for (int n = 0; n < N; n++) {
      if (((mask & A[n]) | (mask & K)) == (mask & K) &&
          ((A[n] >> i) & 1) == 0) {
        tmp += B[n];
      }
    }
    // cerr << i << " " << tmp << " " << static_cast<std::bitset<MAX> >(mask) <<
    // " " << mask2 << endl;
    ans = max(tmp, ans);
  }

  LL tmp = 0;
  for (int i = 0; i < N; i++) {
    if ((A[i] | K) == K) {
      tmp += B[i];
    }
  }

  ans = max(ans, tmp);

  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi 1
#define LL long long
#define ULL unsigned long long
#define LD long double

using namespace std;

#define MAX_N 100005

LL N, K;
LL A[MAX_N], B[MAX_N];

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

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

  LL ans = 0;
  const LL MAX = 31;
  for (int i = 0; i < MAX; i++) {
    if (!((K >> i) & 1)) {
      continue;
    }
    LL mask = pow(2, MAX) - 1;
    LL mask2 = pow(2, i) - 1;
    mask <<= (i + 1);
    LL tmp = 0;
    for (int n = 0; n < N; n++) {
      if (((mask & A[n]) | (mask & K)) == (mask & K) &&
          ((A[n] >> i) & 1) == 0) {
        tmp += B[n];
      }
    }
    // cerr << i << " " << tmp << " " << static_cast<std::bitset<MAX> >(mask) <<
    // " " << mask2 << endl;
    ans = max(tmp, ans);
  }

  LL tmp = 0;
  for (int i = 0; i < N; i++) {
    if ((A[i] | K) == K) {
      tmp += B[i];
    }
  }

  ans = max(ans, tmp);

  cout << ans << endl;

  return 0;
}
Problem p03584 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l, m, rt << 1
#define rs m + 1, r, rt << 1 | 1

using namespace std;

const double g = 10.0, eps = 1e-7;
const int N = 200 + 10, maxn = 60000 + 10, inf = 0x3f3f3f;

int f[32];
int a[N], b[N];
int main() {
  for (int i = 0; i < 31; i++)
    f[i] = (1 << i);
  int n, k;
  scanf("%d%d", &n, &k);
  ll res = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    if ((a[i] & k) == a[i])
      res += b[i];
  }
  for (int i = 30; i >= 0; i--) {
    if (k & f[i]) {
      ll ans = 0, te = (k ^ f[i]) | (f[i] - 1);
      for (int j = 0; j < n; j++)
        if ((te & a[j]) == a[j])
          ans += b[j];
      res = max(res, ans);
    }
  }
  printf("%lld\n", res);
  return 0;
}
/********************

********************/


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l, m, rt << 1
#define rs m + 1, r, rt << 1 | 1

using namespace std;

const double g = 10.0, eps = 1e-7;
const int N = 200000 + 10, maxn = 60000 + 10, inf = 0x3f3f3f;

int f[32];
int a[N], b[N];
int main() {
  for (int i = 0; i < 31; i++)
    f[i] = (1 << i);
  int n, k;
  scanf("%d%d", &n, &k);
  ll res = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    if ((a[i] & k) == a[i])
      res += b[i];
  }
  for (int i = 30; i >= 0; i--) {
    if (k & f[i]) {
      ll ans = 0, te = (k ^ f[i]) | (f[i] - 1);
      for (int j = 0; j < n; j++)
        if ((te & a[j]) == a[j])
          ans += b[j];
      res = max(res, ans);
    }
  }
  printf("%lld\n", res);
  return 0;
}
/********************

********************/
Problem p03584 (C++)

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) { cin >> a[i] >> b[i]; }
  vector<ll> z;
  ll mask = 0;
  for (ll i = 63 - __builtin_clzll(k); i >= 0; i--) {
    ll an = 0;
    mask += (1LL << i);
    if (((k >> i) & 1LL) == 0)
      continue;
    rep(j, n) {
      if ((a[j] & mask) == 0 && a[j] <= k)
        an += b[j];
    }
    mask -= (1LL << i);
    ans = max(ans, an);
  }
  ll ann = 0;
  rep(j, n) {
    if ((a[j] & mask) == 0 && a[j] <= k)
      ann += b[j];
  }
  ans = max(ans, ann);
  cout << ans << endl;
  return 0;
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) { cin >> a[i] >> b[i]; }
  vector<ll> z;
  ll mask = 0;
  if (k == 0) {
    rep(i, n) if (a[i] == 0) ans += b[i];
    cout << ans << endl;
    return 0;
  }
  for (ll i = 63 - __builtin_clzll(k); i >= 0; i--) {
    ll an = 0;
    mask += (1LL << i);
    if (((k >> i) & 1LL) == 0)
      continue;
    rep(j, n) {
      if ((a[j] & mask) == 0 && a[j] <= k)
        an += b[j];
    }
    mask -= (1LL << i);
    ans = max(ans, an);
  }
  ll ann = 0;
  rep(j, n) {
    if ((a[j] & mask) == 0 && a[j] <= k)
      ann += b[j];
  }
  ans = max(ans, ann);
  cout << ans << endl;
  return 0;
}
Problem p03584 (C++)

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

#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, x, n) for (int i = x; i >= n; i--)
#define rrep(i, n) RREP(i, n, 0)
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int, int>;

const int mod = 1e9 + 7, INF = 1 << 30;
const double EPS = 1e-12, PI = 3.1415926535897932384626;
const ll LINF = 1LL << 60, lmod = 1e9 + 7;

const int MAX_N = 2003;
int a[MAX_N];
ll b[MAX_N];

int main() {
  int N, K;
  cin >> N >> K;
  rep(i, N) scanf("%d%lld", a + i, b + i);
  ll ans = 0LL, temp = 0LL;
  rep(i, N) if ((a[i] | K) == K) ans += b[i];
  rep(i, 30) {
    if ((K & (1 << i)) == 0)
      continue;
    int t = (K ^ (1 << i)) | ((1 << i) - 1);
    temp = 0LL;
    rep(i, N) if ((a[i] | t) == t) temp += b[i];
    ans = max(ans, temp);
  }
  cout << ans << endl;
  return 0;
}

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

#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, x, n) for (int i = x; i >= n; i--)
#define rrep(i, n) RREP(i, n, 0)
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int, int>;

const int mod = 1e9 + 7, INF = 1 << 30;
const double EPS = 1e-12, PI = 3.1415926535897932384626;
const ll LINF = 1LL << 60, lmod = 1e9 + 7;

const int MAX_N = 100005;
int a[MAX_N];
ll b[MAX_N];

int main() {
  int N, K;
  cin >> N >> K;
  rep(i, N) scanf("%d%lld", a + i, b + i);
  ll ans = 0LL, temp = 0LL;
  rep(i, N) if ((a[i] | K) == K) ans += b[i];
  rep(i, 30) {
    if ((K & (1 << i)) == 0)
      continue;
    int t = (K ^ (1 << i)) | ((1 << i) - 1);
    temp = 0LL;
    rep(i, N) if ((a[i] | t) == t) temp += b[i];
    ans = max(ans, temp);
  }
  cout << ans << endl;
  return 0;
}
Problem p03584 (C++)

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

using namespace std;

const int N = 1e5 + 5;

long long a[N], b[N];

int main() {
  int n;
  long long k;
  scanf("%d %lld", &n, &k);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", a + i, b + i);
    if ((k & a[i]) == a[i])
      ans += b[i];
  }
  for (long long mask = 1; mask <= k; mask <<= 1) {
    if ((k & mask) == 0)
      continue;
    long long now = (mask ^ k) | (mask - 1);
    assert(now >= k);
    long long cur = 0;
    for (int i = 0; i < n; i++) {
      if ((now & a[i]) == a[i])
        cur += b[i];
    }
    ans = max(ans, cur);
  }
  printf("%lld\n", ans);
  return 0;
}

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

using namespace std;

const int N = 1e5 + 5;

long long a[N], b[N];

int main() {
  int n;
  long long k;
  scanf("%d %lld", &n, &k);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", a + i, b + i);
    if ((k & a[i]) == a[i])
      ans += b[i];
  }
  for (long long mask = 1; mask <= k; mask <<= 1) {
    if ((k & mask) == 0)
      continue;
    long long now = (mask ^ k) | (mask - 1);
    long long cur = 0;
    for (int i = 0; i < n; i++) {
      if ((now & a[i]) == a[i])
        cur += b[i];
    }
    ans = max(ans, cur);
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03584 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <stdio.h>
using namespace std;
long long k, ans, a[11111], b[11111], ff[44], k1, qq, ta, ta1;
int n, u;
int main() {
  scanf("%d%lld", &n, &k);
  ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &a[i], &b[i]);
    if ((a[i] | k) == k)
      ans += b[i];
  }
  k1 = k;
  u = 0;
  while (k1 != 0) {
    u++;
    ff[u] = k1 % 2;
    k1 /= 2;
  }
  for (int i = u; i > 0; i--) {
    if (ff[i] == 1) {
      qq = 0;
      ta1 = ta * 2;
      for (int j = 1; j < i; j++)
        ta1 = ta1 * 2 + 1;
      for (int j = 1; j <= n; j++) {
        if ((a[j] | ta1) == ta1)
          qq += b[j];
      }
      if (qq > ans)
        ans = qq;
      ta = ta * 2 + 1;
    } else
      ta *= 2;
  }
  printf("%lld\n", ans);
}


Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <stdio.h>
using namespace std;
long long k, ans, a[111111], b[111111], ff[44], k1, qq, ta, ta1;
int n, u;
int main() {
  scanf("%d%lld", &n, &k);
  ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &a[i], &b[i]);
    if ((a[i] | k) == k)
      ans += b[i];
  }
  k1 = k;
  u = 0;
  while (k1 != 0) {
    u++;
    ff[u] = k1 % 2;
    k1 /= 2;
  }
  for (int i = u; i > 0; i--) {
    if (ff[i] == 1) {
      qq = 0;
      ta1 = ta * 2;
      for (int j = 1; j < i; j++)
        ta1 = ta1 * 2 + 1;
      for (int j = 1; j <= n; j++) {
        if ((a[j] | ta1) == ta1)
          qq += b[j];
      }
      if (qq > ans)
        ans = qq;
      ta = ta * 2 + 1;
    } else
      ta *= 2;
  }
  printf("%lld\n", ans);
}
Problem p03584 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b)                                                            \
  {                                                                            \
    if (a < b)                                                                 \
      a = b;                                                                   \
  }
#define chmin(a, b)                                                            \
  {                                                                            \
    if (a > b)                                                                 \
      a = b;                                                                   \
  }
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF = 1e18;
static const ll MAX = 1e5 + 7;
static const ll MOD = 1e9 + 7;

int main() {
  ll N, K;
  cin >> N >> K;
  ll a[5555], b[5555];
  ll i, j;

  for (i = 0; i < N; i++)
    cin >> a[i] >> b[i];

  ll ans = 0;

  for (i = 0; i < N; i++) {
    if ((K | a[i]) == K)
      ans += b[i];
  }

  for (i = 30; i >= 0; i--) {
    if (!(1 & K >> i))
      continue;

    ll mask = K - (1 << i) | ((1 << i) - 1);
    ll s = 0;
    for (j = 0; j < N; j++) {
      if ((mask | a[j]) == mask)
        s += b[j];
    }

    chmax(ans, s);
  }

  pt(ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b)                                                            \
  {                                                                            \
    if (a < b)                                                                 \
      a = b;                                                                   \
  }
#define chmin(a, b)                                                            \
  {                                                                            \
    if (a > b)                                                                 \
      a = b;                                                                   \
  }
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF = 1e18;
static const ll MAX = 1e5 + 7;
static const ll MOD = 1e9 + 7;

int main() {
  ll N, K;
  cin >> N >> K;
  ll a[MAX], b[MAX];
  ll i, j;

  for (i = 0; i < N; i++)
    cin >> a[i] >> b[i];

  ll ans = 0;

  for (i = 0; i < N; i++) {
    if ((K | a[i]) == K)
      ans += b[i];
  }

  for (i = 30; i >= 0; i--) {
    if (!(1 & K >> i))
      continue;

    ll mask = K - (1 << i) | ((1 << i) - 1);
    ll s = 0;
    for (j = 0; j < N; j++) {
      if ((mask | a[j]) == mask)
        s += b[j];
    }

    chmax(ans, s);
  }

  pt(ans);
}
Problem p03584 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 4005
#define eps 1e-10
// #define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T> void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
int N, K;
int A[MAXN], B[MAXN];
int64 ans;
int lowbit(int x) { return x & (-x); }
void Calc(int v) {
  int64 res = 0;
  for (int i = 1; i <= N; ++i) {
    if ((v & A[i]) == A[i])
      res += B[i];
  }
  ans = max(ans, res);
}
void Solve() {
  read(N);
  read(K);
  for (int i = 1; i <= N; ++i) {
    read(A[i]);
    read(B[i]);
  }
  Calc(K);
  while (K) {
    int t = lowbit(K);
    int h = K - 1;
    K -= t;
    Calc(h);
  }
  out(ans);
  enter;
}
int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Solve();
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-10
// #define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T> void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
int N, K;
int A[MAXN], B[MAXN];
int64 ans;
int lowbit(int x) { return x & (-x); }
void Calc(int v) {
  int64 res = 0;
  for (int i = 1; i <= N; ++i) {
    if ((v & A[i]) == A[i])
      res += B[i];
  }
  ans = max(ans, res);
}
void Solve() {
  read(N);
  read(K);
  for (int i = 1; i <= N; ++i) {
    read(A[i]);
    read(B[i]);
  }
  Calc(K);
  while (K) {
    int t = lowbit(K);
    int h = K - 1;
    K -= t;
    Calc(h);
  }
  out(ans);
  enter;
}
int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Solve();
}
Problem p03584 (C++)

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

int a[10101], b[10101];

signed main(void) {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  // 先ずはmskを変更しない
  int sum = 0;

  for (int i = 0; i < n; i++) {
    bool ok = true;

    for (int j = 0; j <= 40; j++) {
      if (!(k >> j & 1LL) && (a[i] >> j & 1)) {
        ok = false;
      }
    }

    if (ok) {
      sum += b[i];
    }
  }

  int ans = sum;
  // 次は0を立てる

  for (int i = 40; i >= 0; i--) {

    sum = 0;

    if (k >> i & 1) { // このビットを０にして、それ未満を全て立てる

      int res = k;
      res = (res >> i) << i;
      res--;

      for (int j = 0; j < n; j++) {

        if ((a[j] | res) == res) {
          sum += b[j];
        }
      }
    }

    ans = max(ans, sum);
  }

  cout << ans << endl;

  return 0;
}

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

int a[101010], b[101010];

signed main(void) {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  // 先ずはmskを変更しない
  int sum = 0;

  for (int i = 0; i < n; i++) {
    bool ok = true;

    for (int j = 0; j <= 40; j++) {
      if (!(k >> j & 1LL) && (a[i] >> j & 1)) {
        ok = false;
      }
    }

    if (ok) {
      sum += b[i];
    }
  }

  int ans = sum;
  // 次は0を立てる

  for (int i = 40; i >= 0; i--) {

    sum = 0;

    if (k >> i & 1) { // このビットを０にして、それ未満を全て立てる

      int res = k;
      res = (res >> i) << i;
      res--;

      for (int j = 0; j < n; j++) {

        if ((a[j] | res) == res) {
          sum += b[j];
        }
      }
    }

    ans = max(ans, sum);
  }

  cout << ans << endl;

  return 0;
}
Problem p03584 (Python)

Buggy submission (status: Runtime Error):
import math

if __name__ == "__main__":
    N, K = list(map(int, input().split()))
    integer_value = []
    for i in range(N):
        integer, value = list(map(int, input().split()))
        integer_value.append((integer, value))
    r = int(math.log(K, 2))
    max_value = 0
    for i in range(r + 1):
        # print((K >> i) & 0b1)
        if not ((K >> i) & 0b1):
            continue

        tmp_sum = 0

        mask = 1
        for j in range(i):
            mask = (mask << 1) + 1
        Ki = (K | mask) - 2**i

        for tmp_int, tmp_val in integer_value:
            if Ki | tmp_int == Ki:
                tmp_sum += tmp_val

        # print(str(tmp_sum) + " " + str(i))
        if max_value < tmp_sum:
            max_value = tmp_sum

    # K の場合
    K_val = 0
    for tmp_int, tmp_val in integer_value:
        if K | tmp_int == K:
            K_val += tmp_val
    # print("max_val" + str(max_value))
    # print("K_val" + str(K_val))
    if K_val < max_value:
        print(max_value)
    else:
        print(K_val)


Fixed submission:
import math

if __name__ == "__main__":
    N, K = list(map(int, input().split()))
    integer_value = []
    for i in range(N):
        integer, value = list(map(int, input().split()))
        integer_value.append((integer, value))
    if K == 0:
        r = 0
    else:
        r = int(math.log(K, 2))
    max_value = 0
    for i in range(r + 1):
        # print((K >> i) & 0b1)
        if not ((K >> i) & 0b1):
            continue

        tmp_sum = 0

        mask = 1
        for j in range(i):
            mask = (mask << 1) + 1
        Ki = (K | mask) - 2**i

        for tmp_int, tmp_val in integer_value:
            if Ki | tmp_int == Ki:
                tmp_sum += tmp_val

        # print(str(tmp_sum) + " " + str(i))
        if max_value < tmp_sum:
            max_value = tmp_sum

    # K の場合
    K_val = 0
    for tmp_int, tmp_val in integer_value:
        if K | tmp_int == K:
            K_val += tmp_val
    # print("max_val" + str(max_value))
    # print("K_val" + str(K_val))
    if K_val < max_value:
        print(max_value)
    else:
        print(K_val)
Problem p03584 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys

input = sys.stdin.readline

N, K = map(int, input().split())
int_list = []
for _ in range(N):
    A, B = map(int, input().split())
    int_list.append([A, B])

K_bin = bin(K)[2:]
max_len = len(K_bin)
for i in range(N):
    int_list[i] = (bin(int_list[i][0])[2:].zfill(max_len), int_list[i][1])

or_list = [K_bin]
for i in range(max_len):
    if K_bin[i] == "1":
        or_list.append(K_bin[:i] + "0" + "1" * (max_len - i - 1))

ans = 0
for k in or_list:
    ans_k = 0
    for A, B in int_list:
        if len(A) > max_len:
            continue
        ok = 1
        for j, a in enumerate(A):
            if a == "1" and k[j] == "0":
                ok = 0
        if ok:
            ans_k += B
    ans = max(ans, ans_k)

print(ans)


Fixed submission:
import sys

input = sys.stdin.readline

N, K = map(int, input().split())
int_list = []
for _ in range(N):
    A, B = map(int, input().split())
    int_list.append([A, B])

K_bin = bin(K)[2:]
max_len = len(K_bin)
for i in range(N):
    int_list[i] = (bin(int_list[i][0])[2:].zfill(max_len), int_list[i][1])

or_list = [K_bin]
for i in range(max_len):
    if K_bin[i] == "1":
        or_list.append(K_bin[:i] + "0" + "1" * (max_len - i - 1))

ans = 0
for k in or_list:
    ans_k = 0
    for A, B in int_list:
        if len(A) > max_len:
            continue
        ok = 1
        for j, a in enumerate(A):
            if a == "1" and k[j] == "0":
                ok = 0
                break
        if ok:
            ans_k += B
    ans = max(ans, ans_k)

print(ans)
Problem p03587 (C++)

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

int main() {
  string s;
  cin >> s;
  int ans;
  for (int i = 0; i < 7; i++) {
    if (s.at(i) == '1')
      ans++;
  }
  cout << ans << endl;
}

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

int main() {
  string s;
  cin >> s;
  int ans;
  for (int i = 0; i < 6; i++) {
    if (s.at(i) == '1')
      ans++;
  }
  cout << ans << endl;
}
Problem p03588 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
int n, a[10001], b[10001], ma;
int main() {
  ma = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if (a[i] > a[ma]) {
      ma = i;
    }
  }
  cout << a[ma] + b[ma] << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int n, a[100001], b[100001], ma;
int main() {
  ma = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if (a[i] > a[ma]) {
      ma = i;
    }
  }
  cout << a[ma] + b[ma] << endl;
  return 0;
}
Problem p03588 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<vector<int>> S(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> S.at(i).at(j);
    }
  }
  int K = S.at(0).at(0);
  int L = S.at(0).at(1);
  for (int i = 0; i < N; i++) {
    if (S.at(i).at(1) < L) {
      K = S.at(i + 1).at(0);
      L = S.at(i + 1).at(1);
    } else
      continue;
  }
  cout << L + K << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<vector<int>> S(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> S.at(i).at(j);
    }
  }
  int K = S.at(0).at(0);
  int L = S.at(0).at(1);
  for (int i = 0; i < N; i++) {
    if (S.at(i).at(1) < L) {
      K = S.at(i).at(0);
      L = S.at(i).at(1);
    } else
      continue;
  }
  cout << L + K << endl;
}
Problem p03588 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <stdio.h>
#include <vector>
using std::vector;

int main() {
  int N, i, j, max;
  std::vector<int> a(100000000), b(100000000);
  scanf("%d", &N);
  for (i = 0; i < N * 2; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < N * 2; i += 2) {
    j = i / 2;
    b[j] = a[i];
  }
  std::vector<int>::iterator iter = max_element(b.begin(), b.end());
  size_t index = distance(b.begin(), iter);
  printf("%d", b[index] + a[index * 2 + 1]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
#include <vector>
using std::vector;

int main() {
  int N, i, j, max;
  std::vector<int> a(10000000), b(10000000);
  scanf("%d", &N);
  for (i = 0; i < N * 2; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < N * 2; i += 2) {
    j = i / 2;
    b[j] = a[i];
  }
  std::vector<int>::iterator iter = max_element(b.begin(), b.end());
  size_t index = distance(b.begin(), iter);
  printf("%d", b[index] + a[index * 2 + 1]);
  return 0;
}
Problem p03588 (C++)

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

using namespace std;

int main(void) {

  int N;
  long long A[10000], B[10000];
  long long ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  long long maxA = 0;
  int num = 0;

  for (int i = 0; i < N; i++) {
    if (A[i] > maxA) {
      maxA = A[i];
      num = B[i];
    }
  }

  ans = maxA + num;

  cout << ans << endl;
}

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

using namespace std;

int main(void) {

  int N;
  long long A[100000], B[100000];
  long long ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  long long maxA = 0;
  int num = 0;

  for (int i = 0; i < N; i++) {
    if (A[i] > maxA) {
      maxA = A[i];
      num = B[i];
    }
  }

  ans = maxA + num;

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

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  long long int a = 0, b[1000], c, max;
  cin >> a;
  for (int i = 0; i < a * 2; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < a * 2; i = i + 2) {
    if (b[i] > max) {
      max = b[i];
      c = b[i + 1];
    }
  }
  cout << max + c << endl;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  long long int a = 0, b[1000000], c = 0, max = 0;
  cin >> a;
  for (int i = 0; i < a * 2; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < a * 2; i = i + 2) {
    if (b[i] > max) {
      max = b[i];
      c = b[i + 1];
    }
  }
  cout << max + c << endl;
}
Problem p03588 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
const int N = 10006;
struct node {
  int x, y;
} a[N];
int n, p, q, s;
void work(void) {
  int i;
  for (i = 1; i <= n; i++)
    if (a[i].x > p) {
      p = a[i].x;
      q = a[i].y;
    }
  s = p + q;
  cout << s;
}
int main(void) {
  int i;
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> a[i].x >> a[i].y;
  work();
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
const int N = 100006;
struct node {
  int x, y;
} a[N];
int n, p, q, s;
void work(void) {
  int i;
  for (i = 1; i <= n; i++)
    if (a[i].x > p) {
      p = a[i].x;
      q = a[i].y;
    }
  s = p + q;
  cout << s;
}
int main(void) {
  int i;
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> a[i].x >> a[i].y;
  work();
  return 0;
}
Problem p03588 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const int MAX_N = 10000;
int n, a, b[10000];

int main() {
  cin >> n;
  int ma = 0;
  REP(i, 0, n) cin >> a >> b[i], ma = max(ma, a);
  sort(b, b + n);

  cout << ma + b[0] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const int MAX_N = 10000;
int n, a, b[100010];

int main() {
  cin >> n;
  int ma = 0;
  REP(i, 0, n) cin >> a >> b[i], ma = max(ma, a);
  sort(b, b + n);

  cout << ma + b[0] << endl;
  return 0;
}
Problem p03588 (C++)

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

int main() {
  using P = pair<int, int>;
  int n;
  cin >> n;
  vector<P> v;
  for (auto &p : v)
    cin >> p.first >> p.second;
  sort(v.begin(), v.end());
  cout << v[n - 1].first + v[n - 1].second << endl;
  return 0;
}


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

int main() {
  using P = pair<int, int>;
  int n;
  cin >> n;
  vector<P> v(n);
  for (auto &p : v)
    cin >> p.first >> p.second;
  sort(v.begin(), v.end());
  cout << v[n - 1].first + v[n - 1].second << endl;
  return 0;
}
Problem p03588 (C++)

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

int main(void) {
  int n;
  cin >> n;
  vector<pair<int, int>> data(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    data[i] = make_pair(a, b);
  }
  int amaxi = 0;
  sort(data.begin(), data.end());
  int f = false;
  for (int i = data[0].first - 1; i > 0; i--) {
    if (data[0].second + data[i].first - i > 1000000001)
      f++;
  }
  int ans = 0;
  if (f > 0)
    ans += data[n - 1].first - f;
  else
    ans += data[n - 1].first;
  ans += data[n - 1].second;
  cout << ans;
  return 0;
}


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

int main(void) {
  int n;
  cin >> n;
  vector<pair<int, int>> data(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    data[i] = make_pair(a, b);
  }
  int amaxi = 0;
  sort(data.begin(), data.end());
  long long ans = 0;
  ans += data[n - 1].first;
  ans += data[n - 1].second;
  cout << ans;
  return 0;
}
Problem p03589 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
using ll = long long;
map<int, int> mpa, mpb;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  for (ll j = 1; j <= 3500; j++) {
    for (ll k = 1; k <= 3500; k++) {
      if (4 / N == (-N * (j + k) + 4 * j * k) / N * j * k + 1 / j + 1 / k &&
          j == int(j) && k == int(k)) {
        cout << j * k / (-N * (j + k) + 4 * j * k) * N << " " << j << " " << k
             << endl;
        return 0;
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
using ll = long long;
map<int, int> mpa, mpb;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  ll h, n, w;
  for (h = 1; h <= 3500; h++) {
    for (n = 1; n <= 3500; n++) {
      if (-N * (h + n) + 4 * h * n <= 0)
        continue;
      if ((h * n * N) % (4 * h * n - N * h - N * n) == 0) {
        cout << h << " " << n << " "
             << (h * n * N) / (4 * h * n - N * h - N * n) << endl;
        return 0;
      }
    }
  }
}
Problem p03589 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for (int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
  ll n;
  cin >> n;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      ll k1 = n * i * j;
      ll k2 = (4 * i * j) - (n * i) - (n * j);
      ll k3 = k1 % k2;
      if (k3 == 0) {
        ll k4 = k1 / k2;
        if (k4 > 0) {
          cout << i << " " << j << " " << k4 << endl;
          return 0;
        }
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for (int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
  ll n;
  cin >> n;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      ll k1 = n * i * j;
      ll k2 = (4 * i * j) - (n * i) - (n * j);
      if (k2 > 0) {
        ll k3 = k1 % k2;
        if (k3 == 0) {
          cout << i << " " << j << " " << k1 / k2 << endl;
          return 0;
        }
      }
    }
  }
}
Problem p03589 (C++)

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

int main() {
  long long int N;
  cin >> N;
  if (N % 2 == 0) {
    cout << N / 2 << " " << N << " " << N;
  } else {
    long long t2;
    for (long long int a = 1; a <= 3500; a++) {

      for (long long int b = a; b <= 3500; b++) {
        for (long long int c = b; c <= 3500; c++) {
          if ((t2 = 4 * a * b * c - N * (a * b + b * c + a * c)) == 0) {
            cout << a << " " << b << " " << c;
            return 0;
          } else if (t2 > 0) {
            break;
          }
        }
      }
    }
  }
}

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

int main() {
  long long int N;
  cin >> N;
  if (N % 2 == 0) {
    cout << N / 2 << " " << N << " " << N;
  } else {
    long long t2;
    for (long long int a = 1; a <= 3500; a++) {

      for (long long int b = 1; b <= 3500; b++) {
        long long int temp1 = a * b * N;
        long long int temp2 = 4 * a * b - a * N - b * N;
        if (temp2 > 0 && temp1 % temp2 == 0) {
          cout << a << " " << b << " " << temp1 / temp2;
          return 0;
        }
      }
    }
  }
}
Problem p03589 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

  for (ll a = 1; a <= 3500; a++) {
    for (ll b = 1; b <= 3500; b++) {
      ll x = n * a * b;
      ll y = 4 * a * b - n * (a + b);
      if (x % y == 0) {
        ll c = x / y;
        cout << a << " " << b << " " << c << endl;
        return 0;
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
  ll N, h, n;
  cin >> N;
  for (h = 1; h < 3501; h++) {
    for (n = 1; n < 3501; n++) {
      if (4 * h * n - N * n - N * h > 0 &&
          N * h * n % (4 * h * n - N * n - N * h) == 0) {
        cout << h << " " << n << " " << N * h * n / (4 * h * n - N * n - N * h)
             << endl;
        return 0;
      }
    }
  }
}
Problem p03589 (C++)

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

int main() {
  long long n, a, b, c;
  cin >> n;
  for (int a = 1; a <= 3500; a++) {
    for (int b = a; b <= 3500; b++) {
      int x = n * a * b;
      int y = 4 * a * b - n * b - n * a;
      if (y >= 0 && x % y == 0) {
        cout << a << " " << b << " " << x / y << endl;
        return 0;
      }
    }
  }

  return 0;
}


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

int main() {
  long long n, a, b, c;
  cin >> n;
  for (int a = 1; a <= 3500; a++) {
    for (int b = 1; b <= 3500; b++) {
      long long x = n * a * b;
      long long y = 4 * a * b - n * (b + a);
      if (y > 0 && x % y == 0) {
        cout << a << " " << b << " " << x / y << endl;
        return 0;
      }
    }
  }

  return 0;
}
Problem p03589 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  long long int a, b, c, n;
  cin >> n;
  if (n % 2 == 0) {
    cout << n / 2 << " " << n << " " << n << endl;
    return 0;
  }
  for (int i = 1; i <= 3500; i++) {
    for (int j = 1; j <= 3500; j++) {
      a = n * i * j;
      b = 4 * i * j - n * i - n * j;
      if (a % b == 0 && b > 0) {
        cout << i << " " << j << " " << a / b << endl;
        return 0;
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  long long int a, b, c, n;
  cin >> n;
  for (int i = 3500; i >= 0; i--) {
    for (int j = 1; j <= 3500; j++) {
      a = n * i * j;
      b = 4 * i * j - n * i - n * j;
      if (a % b == 0 && b > 0) {
        cout << i << " " << j << " " << a / b << endl;
        return 0;
      }
    }
  }
}
Problem p03589 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  long long N;
  cin >> N;
  for (long long I = 1; 3500 >= I; I++) {
    for (long long J = 1; 3500 >= J; J++) {
      if (!(N * J * I % (4 * J * I - N * I - N * J)) &&
          (N * J * I / (4 * J * I - N * I - N * J)) > 0) {
        cout << I << " " << J << " " << N * J * I / (4 * J * I - N * I - N * J)
             << endl;
        return 0;
      }
    }
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long N;
  cin >> N;
  for (long long I = 1; 3500 >= I; I++) {
    for (long long J = 1; 3500 >= J; J++) {
      if (!(4 * J * I - N * I - N * J))
        continue;
      if (!(N * J * I % (4 * J * I - N * I - N * J)) &&
          (N * J * I / (4 * J * I - N * I - N * J)) > 0) {
        cout << I << " " << J << " " << N * J * I / (4 * J * I - N * I - N * J)
             << endl;
        return 0;
      }
    }
  }
}
Problem p03589 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long N;
  cin >> N;
  for (long i = 1; i <= 3500; i++) {
    for (long j = 1; j <= 3500; j++) {
      if ((N * i * j) % (4 * i * j - N * i - N * j) == 0) {
        cout << (N * i * j) / (4 * i * j - N * i - N * j) << endl;
        return 0;
      }
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long N;
  cin >> N;
  for (long i = 1; i <= 3500; i++) {
    for (long j = 1; j <= 3500; j++) {
      if ((4 * i * j - N * i - N * j) == 0)
        continue;
      if ((N * i * j) % (4 * i * j - N * i - N * j) == 0 &&
          (N * i * j) / (4 * i * j - N * i - N * j) > 0) {
        cout << i << ' ' << j << ' '
             << (N * i * j) / (4 * i * j - N * i - N * j) << endl;
        return 0;
      }
    }
  }
}
Problem p03589 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
  ll N;
  cin >> N;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      ll a = N * i * j;
      ll b = (4 * i * j) - (N * i) - (N * j);
      if (a % b == 0 && a > 0 && b > 0) {
        cout << i << " " << j << " " << a / b << endl;
        return 0;
      }
    }
  }
  return 0;
}


Fixed submission:
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
  ll N;
  cin >> N;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      ll a = N * i * j;
      ll b = (4 * i * j) - (N * i) - (N * j);
      if (a > 0 && b > 0 && a % b == 0) {
        cout << i << " " << j << " " << a / b << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p03589 (C++)

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

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

  const int MAX = 3500;

  for (int i = 1; i <= MAX; i++) {
    for (int j = i + 1; j <= MAX; j++) {
      long long numerator = n * 1LL * i * j;
      long long denominator = 4LL * i * j - (i + j) * 1LL * n;

      if (numerator % denominator == 0 && numerator / denominator > 0) {
        long long k = numerator / denominator;

        printf("%d %d %lld\n", i, j, k);

        return 0;
      }
    }
  }
  return 0;
}


Fixed submission:
#include <cstdio>

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

  const int MAX = 3500;

  for (int i = 1; i <= MAX; i++) {
    for (int j = i + 1; j <= MAX; j++) {
      long long numerator = n * 1LL * i * j;
      long long denominator = 4LL * i * j - (i + j) * 1LL * n;

      if (denominator > 0 && numerator % denominator == 0) {
        long long k = numerator / denominator;

        printf("%d %d %lld\n", i, j, k);

        return 0;
      }
    }
  }
  return 0;
}
Problem p03589 (C++)

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

using namespace std;

#define int long long

const int INF = 1e9;
const int MAX_V = 1000;

signed main() {

  int n;
  cin >> n;

  for (int i = 1; i < 3600; i++) {
    for (int j = 1; j < 3600; j++) {
      if (n * i * j > 0 && (n * i * j) % (4 * i * j - (i + j) * n) == 0) {
        cout << i << " " << j << " " << (n * i * j) / (4 * i * j - (i + j) * n)
             << endl;
        return 0;
      }
    }
  }
}

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

using namespace std;

#define int long long

const int INF = 1e9;
const int MAX_V = 1000;

signed main() {

  int n;
  cin >> n;

  for (int i = 1; i < 3600; i++) {
    for (int j = 1; j < 3600; j++) {
      if (4 * i * j - (i + j) * n > 0 &&
          (n * i * j) % (4 * i * j - (i + j) * n) == 0) {
        cout << i << " " << j << " " << (n * i * j) / (4 * i * j - (i + j) * n)
             << endl;
        return 0;
      }
    }
  }
}
Problem p03590 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
#define mst(a, b) memset((a), (b), sizeof(a))
#define rush()                                                                 \
  int T;                                                                       \
  scanf("%d", &T);                                                             \
  while (T--)

typedef long long ll;
const int maxn = 3505;
const ll mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;

int a[maxn], b[maxn];
int jie[maxn];

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if ((a[i] | k) == k)
      ans += b[i];
  }
  jie[0] = 1;
  for (int i = 1; i <= 29; i++) {
    jie[i] = jie[i - 1] * 2;
  }
  for (int i = 1; i <= 29; i++) {
    if (k & jie[i]) {
      int temp = (k ^ jie[i]) | (jie[i] - 1);
      ll cnt = 0;
      for (int j = 1; j <= n; j++) {
        if ((a[j] | temp) == temp)
          cnt += b[j];
      }
      ans = max(ans, cnt);
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
#define mst(a, b) memset((a), (b), sizeof(a))
#define rush()                                                                 \
  int T;                                                                       \
  scanf("%d", &T);                                                             \
  while (T--)

typedef long long ll;
const int maxn = 100005;
const ll mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;

int a[maxn], b[maxn];
int jie[maxn];

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if ((a[i] | k) == k)
      ans += b[i];
  }
  jie[0] = 1;
  for (int i = 1; i <= 29; i++) {
    jie[i] = jie[i - 1] * 2;
  }
  for (int i = 1; i <= 29; i++) {
    if (k & jie[i]) {
      int temp = (k ^ jie[i]) | (jie[i] - 1);
      ll cnt = 0;
      for (int j = 1; j <= n; j++) {
        if ((a[j] | temp) == temp)
          cnt += b[j];
      }
      ans = max(ans, cnt);
    }
  }
  printf("%lld\n", ans);
  return 0;
}