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

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

long long layer_num[51], patty_num[51];

long long getPatty(long long level, long long x) {
  if (level == 0 && x == 1) {
    return 1;
  } else if (level == 0 && x != 0) {
    return 0;
  } else {
    if (x < layer_num[level - 1] + 1) {
      return getPatty(level - 1, x - 1);
    } else if (x == layer_num[level - 1] + 1) {
      return patty_num[level - 1];
    } else if (x == layer_num[level - 1] + 2) {
      return patty_num[level - 1] + 1;
    } else if (x == 2 * layer_num[level - 1] + 2 ||
               x == 2 * layer_num[level - 1] + 3) {
      return 2 * patty_num[level - 1] + 1;
    } else {
      return patty_num[level - 1] + 1 +
             getPatty(level - 1, x - (layer_num[level - 1] + 2));
    }
  }
}

int main() {
  long long N, X;
  cin >> N >> X;

  layer_num[0] = 1;
  patty_num[0] = 1;
  for (int i = 1; i <= 50; i++) {
    layer_num[i] = 2 * layer_num[i - 1] + 3;
    patty_num[i] = 2 * patty_num[i - 1] + 1;
  }

  long long ans = getPatty(N, X);
  cout << ans << endl;
}

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

long long layer_num[51], patty_num[51];

long long getPatty(long long level, long long x) {
  if (level == 0 && x == 1) {
    return 1;
  } else if (level == 0 && x != 1) {
    return 0;
  } else {
    if (x < layer_num[level - 1] + 1) {
      return getPatty(level - 1, x - 1);
    } else if (x == layer_num[level - 1] + 1) {
      return patty_num[level - 1];
    } else if (x == layer_num[level - 1] + 2) {
      return patty_num[level - 1] + 1;
    } else if (x == 2 * layer_num[level - 1] + 2 ||
               x == 2 * layer_num[level - 1] + 3) {
      return 2 * patty_num[level - 1] + 1;
    } else {
      return patty_num[level - 1] + 1 +
             getPatty(level - 1, x - (layer_num[level - 1] + 2));
    }
  }
}

int main() {
  long long N, X;
  cin >> N >> X;

  layer_num[0] = 1;
  patty_num[0] = 1;
  for (int i = 1; i <= 50; i++) {
    layer_num[i] = 2 * layer_num[i - 1] + 3;
    patty_num[i] = 2 * patty_num[i - 1] + 1;
  }

  long long ans = getPatty(N, X);
  cout << ans << endl;
}
Problem p03209 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

int n;
ll x;
ll h[51], p[51];
ll dfs(ll n, ll x) {
  if (n == 0 && x > 0)
    return 1;
  if (n == 0 && x == 0)
    return 0;
  if (x <= h[n - 1] + 1)
    return dfs(n - 1, x - 1);
  return dfs(n - 1, x - h[n - 1] - 2) + p[n - 1] + 1;
}
int main() {
  cin >> n >> x;
  h[0] = 1, p[0] = 1;
  FOR(i, 1, n) {
    h[i] = h[i - 1] * 2 + 3;
    p[i] = p[i - 1] * 2 + 1;
  }
  cout << dfs(n, x) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

int n;
ll x;
ll h[51], p[51];
ll dfs(ll n, ll x) {
  if (n == 0 && x > 0)
    return 1;
  if (n == 0 && x <= 0)
    return 0;
  if (x <= h[n - 1] + 1)
    return dfs(n - 1, x - 1);
  return dfs(n - 1, x - h[n - 1] - 2) + p[n - 1] + 1;
}
int main() {
  cin >> n >> x;
  h[0] = 1, p[0] = 1;
  FOR(i, 1, n) {
    h[i] = h[i - 1] * 2 + 3;
    p[i] = p[i - 1] * 2 + 1;
  }
  cout << dfs(n, x) << endl;
  return 0;
}
Problem p03209 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
#define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr)
#define P pair<int, int>
const int MOD = 998244353;
const ll INF = 2e15;
const double PI = acos(-1);

vector<ll> a(55), p(55);

ll f(ll n, ll x) {
  if (n == 0 && x > 1)
    return 1;
  else if (x <= n)
    return 0;
  else if (x <= 1 + a[n - 1])
    return f(n - 1, x - 1);
  else if (x == 2 + a[n - 1])
    return p[n - 1] + 1;
  else
    return p[n - 1] + 1 + f(n - 1, x - a[n - 1] - 2);
}

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

  ll n, x;
  cin >> n >> x;
  a[0] = 1;
  p[0] = 1;
  rep(i, n) {
    a[i + 1] = 2 * a[i] + 3;
    p[i + 1] = 2 * p[i] + 1;
  }
  cout << f(n, x) << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
#define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr)
#define P pair<int, int>
const int MOD = 998244353;
const ll INF = 2e15;
const double PI = acos(-1);

vector<ll> a(55), p(55);

ll f(ll n, ll x) {
  if (n == 0)
    return 1;
  else if (x <= n)
    return 0;
  else if (x <= 1 + a[n - 1])
    return f(n - 1, x - 1);
  else if (x == 2 + a[n - 1])
    return p[n - 1] + 1;
  else
    return p[n - 1] + 1 + f(n - 1, x - a[n - 1] - 2);
}

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

  ll n, x;
  cin >> n >> x;
  a[0] = 1;
  p[0] = 1;
  rep(i, n) {
    a[i + 1] = 2 * a[i] + 3;
    p[i + 1] = 2 * p[i] + 1;
  }
  cout << f(n, x) << endl;

  return 0;
}
Problem p03209 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define DEBUG 0

#define lli long long unsigned int
#define REP(i, n) for (int i = 0; i < n; i++)

using namespace std;

vector<lli> a, b, p;

lli calc(lli level, lli num) {
  lli right = 0;
  lli left = a[level] - 1;
  lli middle = (right + left) / 2;
  if (DEBUG)
    cout << "level=" << level << " num= " << num << endl;

  if (level == 0)
    return 1;

  if (num == 0)
    return 0;
  else if (num < middle) {
    return calc(level - 1, num - 1);
  } else if (num == middle) {
    return p[level - 1] + 1;
  } else if (middle < num) {
    return p[level - 1] + 1 + calc(level - 1, num - middle - 1);
  } else {
    return p[level];
  }
}

int main() {

  lli n, x;
  cin >> n >> x;
  a.resize(n);
  b.resize(n);
  p.resize(n);
  a[0] = 1;
  b[0] = 0;
  p[0] = 1;
  lli d = 2;
  for (lli i = 1; i <= n; i++) {
    b[i] = b[i - 1] + d;
    p[i] = p[i - 1] + d;
    a[i] = b[i] + p[i];
    d *= 2;
  }

  cout << calc(n, x - 1) << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define DEBUG 0

#define lli long long unsigned int
#define REP(i, n) for (int i = 0; i < n; i++)

using namespace std;

vector<lli> a, b, p;

lli calc(lli level, lli num) {
  lli right = 0;
  lli left = a[level] - 1;
  lli middle = (right + left) / 2;
  if (DEBUG)
    cout << "level=" << level << " num= " << num << endl;

  if (level == 0)
    return 1;

  if (num == 0)
    return 0;
  else if (num < middle) {
    return calc(level - 1, num - 1);
  } else if (num == middle) {
    return p[level - 1] + 1;
  } else if (middle < num) {
    return p[level - 1] + 1 + calc(level - 1, num - middle - 1);
  } else {
    return p[level];
  }
}

int main() {

  lli n, x;
  cin >> n >> x;
  a.resize(n + 1);
  b.resize(n + 1);
  p.resize(n + 1);
  a[0] = 1;
  b[0] = 0;
  p[0] = 1;
  lli d = 2;
  for (lli i = 1; i <= n; i++) {
    b[i] = b[i - 1] + d;
    p[i] = p[i - 1] + d;
    a[i] = b[i] + p[i];
    d *= 2;
  }

  cout << calc(n, x - 1) << endl;

  return 0;
}
Problem p03209 (C++)

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

#define MAX 50

long long N;
long long X;

long long num[MAX + 1][2];

long long dfs(long long n, long long x, long long add) {
  if (n > 0 && x <= n) {
    return add;
  } else if (num[n][0] - n <= x && x <= num[n][0]) {
    return num[n][1] + add;
  } else if (x <= num[n - 1][0] - (n - 1) + 1) {
    return dfs(n - 1, x - 1, add);
  } else if (num[n - 1][0] - (n - 1) + 1 <= x && x <= num[n - 1][0] + 1) {
    return num[n - 1][1] + add;
  } else if (num[n - 1][0] + 1 < x && x <= num[n - 1][0] + 2) {
    return num[n - 1][1] + 1 + add;
  }
  return dfs(n - 1, x - (num[n - 1][0] + 2), add + num[n - 1][1] + 1);
}

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

  num[0][0] = 1;
  num[0][1] = 1;
  for (int i = 0; i < 51; i++) {
    num[i + 1][0] = num[i][0] + (1LL << (i + 1)) * 2;
    num[i + 1][1] = num[i][1] + (1LL << (i + 1));
  }

  long long ans = dfs(N, X, 0);

  cout << ans << endl;

  return 0;
}


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

#define MAX 50

long long N;
long long X;

long long num[MAX + 1][2];

long long dfs(long long n, long long x, long long add) {
  if (n > 0 && x <= n) {
    return add;
  } else if (num[n][0] - n <= x && x <= num[n][0]) {
    return num[n][1] + add;
  } else if (x <= num[n - 1][0] - (n - 1) + 1) {
    return dfs(n - 1, x - 1, add);
  } else if (num[n - 1][0] - (n - 1) + 1 <= x && x <= num[n - 1][0] + 1) {
    return num[n - 1][1] + add;
  } else if (num[n - 1][0] + 1 < x && x <= num[n - 1][0] + 2) {
    return num[n - 1][1] + 1 + add;
  }
  return dfs(n - 1, x - (num[n - 1][0] + 2), add + num[n - 1][1] + 1);
}

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

  num[0][0] = 1;
  num[0][1] = 1;
  for (int i = 0; i < 50; i++) {
    num[i + 1][0] = num[i][0] + (1LL << (i + 1)) * 2;
    num[i + 1][1] = num[i][1] + (1LL << (i + 1));
  }

  long long ans = dfs(N, X, 0);

  cout << ans << endl;

  return 0;
}
Problem p03209 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mod 1000000007
ll power(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b % 2 != 0)
      res = (res * a);
    a = (a * a);
    b /= 2;
  }
  return res;
}
ll ncr(ll n, ll k) {
  if (k == 0 || k == n)
    return 1ll;
  if (k > n - k)
    k = n - k;
  ll pro = 1;
  for (ll i = 0; i < k; i++) {
    pro = (pro * (n - i));
    pro /= (i + 1);
  }
  return pro;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, k;
  cin >> n >> k;
  vector<ll> siz, pat;
  siz.push_back(1ll);
  pat.push_back(1ll);
  for (int i = 1; i <= n; i++) {
    siz.push_back(2 * siz[i - 1] + 3ll);
    pat.push_back(2 * pat[i - 1] + 1ll);
  }
  ll ans = 0;
  for (ll i = n; i >= 0; i--) {
    if (k == siz[i]) {
      ans += pat[i];
      break;
    } else if (k == 1ll || k == 0ll) {
      break;
    }
    assert(i > 1);
    if (k <= 1ll + siz[i - 1]) {
      k--;
    } else {
      ans += 1ll + pat[i - 1];
      k -= (2ll + siz[i - 1]);
    }
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mod 1000000007
ll power(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b % 2 != 0)
      res = (res * a);
    a = (a * a);
    b /= 2;
  }
  return res;
}
ll ncr(ll n, ll k) {
  if (k == 0 || k == n)
    return 1ll;
  if (k > n - k)
    k = n - k;
  ll pro = 1;
  for (ll i = 0; i < k; i++) {
    pro = (pro * (n - i));
    pro /= (i + 1);
  }
  return pro;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, k;
  cin >> n >> k;
  vector<ll> siz, pat;
  siz.push_back(1ll);
  pat.push_back(1ll);
  for (int i = 1; i <= n; i++) {
    siz.push_back(2 * siz[i - 1] + 3ll);
    pat.push_back(2 * pat[i - 1] + 1ll);
  }
  ll ans = 0;
  for (ll i = n; i >= 0; i--) {
    if (k == siz[i]) {
      ans += pat[i];
      break;
    } else if (k == 1ll || k == 0ll) {
      break;
    }
    assert(i > 0);
    if (k <= 1ll + siz[i - 1]) {
      k--;
    } else {
      ans += 1ll + pat[i - 1];
      k -= (2ll + siz[i - 1]);
    }
  }
  cout << ans;
  return 0;
}
Problem p03209 (C++)

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

ll cntp(ll n) {
  if (n == 0)
    return 1LL;
  return 2 * cntp(n - 1) + 1;
}

ll volm(ll n) {
  if (n == 0)
    return 1LL;
  return 2 * volm(n - 1) + 3;
}

ll f(ll n, ll x) {
  if (n == 0) {
    if (x == 0)
      return 0; // いくら n == 0 でも、x == 0 なら 0
    else
      return 1LL;
  }

  if (x == 1 && n > 0)
    return 0;
  else if (2 <= x && x <= volm(n - 1) + 1) {
    return f(n - 1, x - 1);
  } else if (volm(n - 1) + 2 <= x && x <= volm(n)) {
    return cntp(n - 1) + 1 + f(n - 1, x - 2 - volm(n - 1));
  }
}

int main(void) {
  ll n, x;
  cin >> n >> x;
  cout << f(n, x) << endl;
  return 0;
}

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

ll cntp(ll n) {
  if (n == 0)
    return 1LL;
  return 2 * cntp(n - 1) + 1;
}

ll volm(ll n) {
  if (n == 0)
    return 1LL;
  return 2 * volm(n - 1) + 3;
}

ll f(ll n, ll x) {
  if (n == 0) {
    if (x == 0)
      return 0; // いくら n == 0 でも、x == 0 なら 0
    else
      return 1LL;
  }

  if (x == 1 || x == 0)
    return 0;
  else if (2 <= x && x <= volm(n - 1) + 1) {
    return f(n - 1, x - 1);
  } else if (volm(n - 1) + 2 <= x && x <= volm(n)) {
    return cntp(n - 1) + 1 + f(n - 1, x - 2 - volm(n - 1));
  }
}

int main(void) {
  ll n, x;
  cin >> n >> x;
  cout << f(n, x) << endl;
  return 0;
}
Problem p03209 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void file() {
#ifndef ONLINE_JUDGE
  freopen("a_input.txt", "r", stdin);
  freopen("a_output.txt", "w", stdout);
#endif
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
ll p[55], a[55];
void build(int n) {
  if (n > 50)
    return;
  p[n] = 2 * p[n - 1] + 1;
  a[n] = 2 * a[n - 1] + 3;
  build(n + 1);
}
ll get(int n, ll x) {
  if (n == 0)
    return x > 0;
  if (x <= a[n - 1] + 1)
    return get(n - 1, x - 1);
  return p[n - 1] + 1 + get(n - 1, x - 2 - a[n - 1]);
}
int main() {
  file();
  fast();
  p[0] = 1;
  a[0] = 1;
  build(1);
  ll n, x;
  cin >> n >> x;
  cout << get(n, x) << endl;
}


Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void file() {
#ifndef ONLINE_JUDGE
  freopen("a_input.txt", "r", stdin);
  freopen("a_output.txt", "w", stdout);
#endif
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
ll p[55], a[55];
void build(int n) {
  if (n > 50)
    return;
  p[n] = 2 * p[n - 1] + 1;
  a[n] = 2 * a[n - 1] + 3;
  build(n + 1);
}
ll get(int n, ll x) {
  if (n == 0)
    return x > 0;
  if (x <= a[n - 1] + 1)
    return get(n - 1, x - 1);
  return p[n - 1] + 1 + get(n - 1, x - 2 - a[n - 1]);
}
int main() {
  // file();
  fast();
  p[0] = 1;
  a[0] = 1;
  build(1);
  ll n, x;
  cin >> n >> x;
  cout << get(n, x) << endl;
}
Problem p03209 (C++)

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

#define INF INT_MAX / 2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

vector<ll> two(52);

ull func(ull N, ll X) {
  if (X <= 0)
    return 0;
  else if (X <= two[N + 1] - 2)
    return func(N - 1, X - 1);
  else
    return func(N - 1, X - two[N + 1] + 1) + two[N];
}

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

  two[0] = 1;
  for (int i = 1; i <= 51; i++)
    two[i] = 2 * two[i - 1];

  ull N, X;
  cin >> N >> X;
  cout << func(N, X) << endl;
  return 0;
}


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

#define INF INT_MAX / 2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

vector<ull> two(52);

ull func(ull N, ll X) {
  if (X <= 0)
    return 0;
  else if (X <= two[N + 1] - 2)
    return func(N - 1, X - 1);
  else
    return func(N - 1, X - two[N + 1] + 1) + two[N];
}

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

  two[0] = 1;
  for (int i = 1; i <= 51; i++)
    two[i] = 2 * two[i - 1];

  ull N, X;
  cin >> N >> X;
  cout << func(N, X) << endl;
  return 0;
}
Problem p03209 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

uint64_t count_p(int l, uint64_t p, const vector<uint64_t> pnum,
                 const vector<uint64_t> bnum, const vector<uint64_t> sum) {
  assert(p <= sum[l]);
  if (l == 0) {
    return 1;
  }
  if (p <= 1) {
    return 0;
  }

  uint64_t spos = 0;
  bool is_rev = false;

  if (p == sum[l] / 2 + 1) {
    return pnum[l] / 2 + 1;
  }

  if (p > sum[l] / 2 + 1) {
    spos = sum[l] - p;
    is_rev = true;
  } else {
    spos = p;
  }

  uint64_t num = count_p(l - 1, spos - 1, pnum, bnum, sum);
  uint64_t ret = is_rev ? pnum[l] - num : num;
  return ret;
}

int main() {
  int l;
  uint64_t p;
  cin >> l >> p;

  // 総数
  vector<uint64_t> pnum(l + 1);
  vector<uint64_t> bnum(l + 1);
  vector<uint64_t> sum(l + 1);
  pnum[0] = 1;
  bnum[0] = 0;
  sum[0] = 1;
  {
    for (int i = 1; i <= l; i++) {
      pnum[i] = (pnum[i - 1] * 2) + 1;
      bnum[i] = (bnum[i - 1] * 2) + 2;
      sum[i] = bnum[i] + pnum[i];
    }
  }

  uint64_t val = count_p(l, p, pnum, bnum, sum);

  cout << val << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

uint64_t count_p(int l, uint64_t p, const vector<uint64_t> pnum,
                 const vector<uint64_t> bnum, const vector<uint64_t> sum) {
  assert(p <= sum[l]);
  if (l == 0) {
    return 1;
  }
  if (p <= 1) {
    return 0;
  }
  if (p >= sum[l] - 1) {
    return pnum[l];
  }

  uint64_t spos = 0;
  bool is_rev = false;

  if (p == sum[l] / 2 + 1) {
    return pnum[l] / 2 + 1;
  }

  if (p > sum[l] / 2 + 1) {
    spos = sum[l] - p;
    is_rev = true;
  } else {
    spos = p;
  }

  uint64_t num = count_p(l - 1, spos - 1, pnum, bnum, sum);
  uint64_t ret = is_rev ? pnum[l] - num : num;
  return ret;
}

int main() {
  int l;
  uint64_t p;
  cin >> l >> p;

  // 総数
  vector<uint64_t> pnum(l + 1);
  vector<uint64_t> bnum(l + 1);
  vector<uint64_t> sum(l + 1);
  pnum[0] = 1;
  bnum[0] = 0;
  sum[0] = 1;
  {
    for (int i = 1; i <= l; i++) {
      pnum[i] = (pnum[i - 1] * 2) + 1;
      bnum[i] = (bnum[i - 1] * 2) + 2;
      sum[i] = bnum[i] + pnum[i];
    }
  }

  uint64_t val = count_p(l, p, pnum, bnum, sum);

  cout << val << endl;

  return 0;
}
Problem p03209 (C++)

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

ll f[55], p[55];

ll F(ll n, ll x) {
  if (n == 0)
    return 1;
  if (x == 1)
    return 0;
  if (x > 1 && x <= f[n - 1] + 1)
    return F(n - 1, x - 1);
  if (x == 2 + f[n - 1])
    return p[n - 1] + 1;
  if (2 + f[n - 1] < x && x <= 2 + 2 * f[n - 1])
    return p[n - 1] + 1 + F(n - 1, x - 2 - f[n - 1]);
  if (x == f[n - 1] * 2 + 3)
    return 2 * p[n - 1] + 1;
}

int main() {
  f[0] = p[0] = 1;
  for (int i = 1; i <= 50; i++) {
    f[i] = 2 * f[i - 1] + 3;
    p[i] = 2 * p[i - 1] + 1;
  }
  ll n;
  ll x;
  scanf("%I64d%I64d", &n, &x);
  printf("%I64d\n", F(n, x));
  return 0;
}

Fixed submission:
#include <cstdio>
#define ll long long
using namespace std;

ll f[55], p[55];

ll F(ll n, ll x) {
  if (n == 0)
    return 1;
  if (x == 1)
    return 0;
  if (x > 1 && x <= f[n - 1] + 1)
    return F(n - 1, x - 1);
  if (x == 2 + f[n - 1])
    return p[n - 1] + 1;
  if (2 + f[n - 1] < x && x <= 2 + 2 * f[n - 1])
    return p[n - 1] + 1 + F(n - 1, x - 2 - f[n - 1]);
  if (x == f[n - 1] * 2 + 3)
    return 2 * p[n - 1] + 1;
}

int main() {
  f[0] = p[0] = 1;
  for (int i = 1; i <= 50; i++) {
    f[i] = 2 * f[i - 1] + 3;
    p[i] = 2 * p[i - 1] + 1;
  }
  ll n;
  ll x;
  scanf("%lld%lld", &n, &x);
  printf("%lld\n", F(n, x));
  return 0;
}
Problem p03209 (C++)

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

vector<long long> l(51);
vector<long long> p(51);

long long solve(int n, long long x) {
  assert(l[n] > x && x >= 0);
  if (n == 1) {
    return x;
  }
  if (x == l[n]) {
    return p[n];
  }
  long long ans = 0;
  if (x > l[n - 1] + 1) {
    ans += p[n - 1] + 1;
    x -= l[n - 1] + 1;
  }
  if (x > 0) {
    ans += solve(n - 1, x - 1);
  }
  return ans;
}

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

  int n;
  long long x;
  cin >> n >> x;
  l[0] = 1LL;
  p[0] = 1LL;
  for (int i = 1; i <= n; i++) {
    l[i] = l[i - 1] * 2 + 3;
    p[i] = p[i - 1] * 2 + 1;
  }
  cout << solve(n, x) << '\n';
}


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

vector<long long> l(51);
vector<long long> p(51);

long long solve(int n, long long x) {
  assert(l[n] >= x && x >= 0);
  if (n == 0) {
    return x;
  }
  if (x == l[n]) {
    return p[n];
  }
  long long ans = 0;
  if (x > l[n - 1] + 1) {
    ans += p[n - 1] + 1;
    x -= l[n - 1] + 1;
  }
  if (x > 0) {
    ans += solve(n - 1, x - 1);
  }
  return ans;
}

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

  int n;
  long long x;
  cin >> n >> x;
  l[0] = 1LL;
  p[0] = 1LL;
  for (int i = 1; i <= n; i++) {
    l[i] = l[i - 1] * 2 + 3;
    p[i] = p[i - 1] * 2 + 1;
  }
  cout << solve(n, x) << '\n';
}
Problem p03209 (C++)

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

int n, k;
int a[100005], b[100005];
int solve(int shift, int size, int pos) {
  if (size == 0)
    return b[shift];
  int mid = (2 * shift + a[size] - 1) / 2;
  if (pos == shift)
    return 0;
  else if (pos < mid)
    return solve(shift + 1, size - 1, pos);
  else if (pos == mid)
    return b[size - 1] + 1;
  else if (pos < shift + a[size] - 1)
    return b[size - 1] + 1 + solve(mid + 1, size - 1, pos);
  else
    return b[size];
}
signed main() {
  a[0] = 1, b[0] = 1;
  for (int i = 1; i <= 50; i++)
    a[i] = 2 * a[i - 1] + 3, b[i] = 2 * b[i - 1] + 1;

  cin >> n >> k;
  // cout << a[n] << " " << b[n] << endl;
  cout << solve(1, n, k);
}


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

int n, k;
int a[100005], b[100005];
int solve(int shift, int size, int pos) {
  if (size == 0)
    return 1;
  int mid = (2 * shift + a[size] - 1) / 2;
  if (pos == shift)
    return 0;
  else if (pos < mid)
    return solve(shift + 1, size - 1, pos);
  else if (pos == mid)
    return b[size - 1] + 1;
  else if (pos < shift + a[size] - 1)
    return b[size - 1] + 1 + solve(mid + 1, size - 1, pos);
  else
    return b[size];
}
signed main() {
  a[0] = 1, b[0] = 1;
  for (int i = 1; i <= 50; i++)
    a[i] = 2 * a[i - 1] + 3, b[i] = 2 * b[i - 1] + 1;

  cin >> n >> k;
  // cout << a[n] << " " << b[n] << endl;
  cout << solve(1, n, k);
}
Problem p03209 (C++)

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

ll f(ll N, ll X) {
  if (X == 0)
    return 0;
  if (N == 0 && X == 1)
    return 1;
  if (X < pow(2, N + 1) - 1)
    return f(N - 1, X - 1);
  if (X == pow(2, N + 1) - 1)
    return pow(2, N);
  if (X > pow(2, N + 1) - 1)
    return pow(2, N) + f(N - 1, X - pow(2, N + 1) + 1);
}

int main() {
  ll N, X;
  cin >> N >> X;
  cout << f(N, X) << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
using ll = long long;

ll f(ll N, ll X) {
  if (X == 0)
    return 0;
  if (X > pow(2, N + 2) - 3)
    return pow(2, N + 1) - 1;
  if (N == 0 && X == 1)
    return 1;
  if (X < pow(2, N + 1) - 1)
    return f(N - 1, X - 1);
  if (X == pow(2, N + 1) - 1)
    return pow(2, N);
  if (X > pow(2, N + 1) - 1)
    return pow(2, N) + f(N - 1, X - pow(2, N + 1) + 1);
}

int main() {
  ll N, X;
  cin >> N >> X;
  cout << f(N, X) << endl;
  return 0;
}
Problem p03209 (C++)

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;

V<ll> len, pat;

ll rec(ll n, ll x) {
  if (n == 0) {
    if (x == 1)
      return 1;
    else
      return 0;
  }
  if (x == 1)
    return 0;
  if (x == len[n])
    return pat[n];

  ll ans = 0;
  if (len[n] / 2 + 1 <= x) {
    ans += pat[n - 1] + 1 + rec(n - 1, x - len[n] / 2 - 1);
  }
  if (len[n] / 2 + 1 > x) {
    ans += rec(n - 1, x - 1);
  }
  return ans;
}

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

  len.resize(n);
  pat.resize(n);
  len[0] = pat[0] = 1;
  for (int i = 1; i <= n; i++) {
    len[i] = len[i - 1] * 2 + 3;
    pat[i] = pat[i - 1] * 2 + 1;
  }
  cout << rec(n, x) << endl;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;

V<ll> len, pat;

ll rec(ll n, ll x) {
  if (n == 0) {
    if (x == 1)
      return 1;
    else
      return 0;
  }
  if (x == 1)
    return 0;
  if (x == len[n])
    return pat[n];

  ll ans = 0;
  if (len[n] / 2 + 1 <= x) {
    ans += pat[n - 1] + 1 + rec(n - 1, x - len[n] / 2 - 1);
  }
  if (len[n] / 2 + 1 > x) {
    ans += rec(n - 1, x - 1);
  }
  return ans;
}

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

  len.resize(n + 1);
  pat.resize(n + 1);
  len[0] = pat[0] = 1;
  for (int i = 1; i <= n; i++) {
    len[i] = len[i - 1] * 2 + 3;
    pat[i] = pat[i - 1] * 2 + 1;
  }
  cout << rec(n, x) << endl;
}
Problem p03209 (C++)

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

ll f(ll n, ll x) {
  if (x == 0)
    return 0;
  if (n == 0)
    return 1;
  if (x <= 1 + b[n - 1])
    return f(n - 1, x - 1);
  else
    return p[n - 1] + 1 + f(n - 1, x - 2 - b[n - 1]);
}

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

  b[0] = p[0] = 1;
  REP(i, n + 1) {
    p[i + 1] = p[i] * 2 + 1;
    b[i + 1] = b[i] * 2 + 3;
  }
  cout << f(n, x) << '\n';
  return 0;
}


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

ll f(ll n, ll x) {
  if (x == 0)
    return 0;
  if (n == 0)
    return 1;
  if (x <= 1 + b[n - 1])
    return f(n - 1, x - 1);
  else
    return p[n - 1] + 1 + f(n - 1, x - 2 - b[n - 1]);
}

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

  b[0] = p[0] = 1;
  REP(i, 50) {
    p[i + 1] = p[i] * 2 + 1;
    b[i + 1] = b[i] * 2 + 3;
  }
  cout << f(n, x) << '\n';
  return 0;
}
Problem p03209 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl

using namespace std;

int main() {

  long long N, X;

  cin >> N >> X;

  long long b = 1;
  long long p = 1;
  for (int i = 0; i < N; i++) {
    b = 2 * b + 3;
    p = 2 * p + 1;
  }

  long long ans = 0;
  while (0 < X) {
    if ((b + 1) / 2 <= X) {
      ans += (p - 1) / 2 + 1;
      X -= (b + 1) / 2;
    } else {
      X--;
    }
    b = (b - 3) / 2;
    p = (p - 1) / 2;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl

using namespace std;

int main() {

  long long N, X;

  cin >> N >> X;

  long long b = 1;
  long long p = 1;
  for (int i = 0; i < N; i++) {
    b = 2 * b + 3;
    p = 2 * p + 1;
  }

  long long ans = 0;
  while (X != 0) {
    if (X == b) {
      ans += p;
      break;
    }
    if (X == 1)
      break;
    if ((b + 1) / 2 == X) {
      ans += (p + 1) / 2;
      break;
    }
    if ((b + 1) / 2 < X) {
      ans += (p + 1) / 2;
      X -= (b + 1) / 2;
    } else {
      X--;
    }
    b = (b - 3) / 2;
    p = (p - 1) / 2;
  }

  cout << ans << endl;

  return 0;
}
Problem p03209 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);

using namespace std;
using Int = long long;
// using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
  Int res = 1;
  while (n > 0) {
    if (n & 1)
      res = (res * x) % MOD; // ビット演算(最下位ビットが1のとき)
    x = (x * x) % MOD;
    n >>= 1; // 右シフト(n = n >> 1)
  }
  return res;
}

template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; }

template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }

Int S[51];
Int P[51];

Int calc(int n, Int x) {
  cout << n << " " << x << endl;
  if (x == 1) {
    return 0;
  }
  if (x == S[n - 1] + 1) {
    return P[n - 1];
  }

  if (x >= (S[n] + 1) / 2)
    return P[n] - calc(n, S[n] - x);
  else
    return calc(n - 1, x - 1);
}

int main() {
  cin.tie(0);

  Int N, X;
  cin >> N >> X;

  P[0] = 1LL;
  S[0] = 1LL;

  for (int i = 1; i <= N; i++) {
    S[i] = S[i - 1] * 2LL + 3LL;
    P[i] = P[i - 1] * 2LL + 1LL;
  }

  cout << calc(N, X) << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);

using namespace std;
using Int = long long;
// using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
  Int res = 1;
  while (n > 0) {
    if (n & 1)
      res = (res * x) % MOD; // ビット演算(最下位ビットが1のとき)
    x = (x * x) % MOD;
    n >>= 1; // 右シフト(n = n >> 1)
  }
  return res;
}

template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; }

template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }

Int S[51];
Int P[51];

Int calc(int n, Int x) {
  if (x == 1 || x == 0) {
    return 0;
  }
  if (x == S[n - 1] + 1) {
    return P[n - 1];
  }

  if (x >= (S[n] + 1) / 2)
    return P[n] - calc(n, S[n] - x);
  else
    return calc(n - 1, x - 1);
}

int main() {
  cin.tie(0);

  Int N, X;
  cin >> N >> X;

  P[0] = 1LL;
  S[0] = 1LL;

  for (int i = 1; i <= N; i++) {
    S[i] = S[i - 1] * 2LL + 3LL;
    P[i] = P[i - 1] * 2LL + 1LL;
  }

  cout << calc(N, X) << endl;
}
Problem p03209 (C++)

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

// aiはlevel iの層の厚さ
// piはlevel iのパティの数
ll a[52], p[52];

ll f(int N, ll X) {
  if (N == 0) {
    if (X <= 0) {
      return 0;
    } else {
      return p[0];
    }
  } else if (X <= (a[N - 1] + 1)) {
    return f(N - 1, X - 1);
  } else if (X == (a[N - 1] + 2)) {
    return f(N - 1, X - 1) + 1;
  } else {
    return f(N - 1, X - 1) + 1 + f(N - 1, X - 2 - a[N - 1]);
  }
}

int main() {
  cout << fixed << setprecision(10);

  int N;
  cin >> N;
  ll X;
  cin >> X;

  a[0] = 1;
  p[0] = 1;
  repr(i, 1, 51) {
    a[i] = a[i - 1] * 2 + 3;
    p[i] = p[i - 1] * 2 + 1;
  }

  cout << f(N, X) << endl;
  return 0;
}

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

// aiはlevel iの層の厚さ
// piはlevel iのパティの数
ll a[52], p[52];

ll f(int N, ll X) {
  if (N == 0) {
    if (X <= 0) {
      return 0;
    } else {
      return p[0];
    }
  } else if (X <= (a[N - 1] + 1)) {
    return f(N - 1, X - 1);
  } else if (X == (a[N - 1] + 2)) {
    return f(N - 1, X - 1) + 1;
  } else {
    return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1]);
  }
}

int main() {
  cout << fixed << setprecision(10);

  int N;
  cin >> N;
  ll X;
  cin >> X;

  a[0] = 1;
  p[0] = 1;
  repr(i, 1, 51) {
    a[i] = a[i - 1] * 2 + 3;
    p[i] = p[i - 1] * 2 + 1;
  }

  cout << f(N, X) << endl;
  return 0;
}
Problem p03209 (C++)

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

__int128 total_level[55];
__int128 total_party[55];

void scan(__int128 &x) // 输入
{
  x = 0;
  int f = 1;
  getchar();
  char ch;
  if ((ch = getchar()) == '-')
    f = -f;
  else
    x = x * 10 + ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9')
    x = x * 10 + ch - '0';
  x *= f;
}

void print(__int128 x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + '0');
}

__int128 solve(int N, __int128 X) {
  if (N == 1) {
    if (X == 0)
      return 0;
    if (X == 1)
      return 0;
    if (X == 2)
      return 1;
    if (X == 3)
      return 2;
    if (X == 4)
      return 3;
    if (X == 5)
      return 3;
  }
  if (X == total_level[N - 1] + 2)
    return total_party[N - 1] + 1;
  if (X == total_level[N - 1] + 1)
    return total_party[N - 1];
  if (X < total_level[N - 1] + 1) {
    return solve(N - 1, X - 1);
  }
  if (X > total_level[N - 1] + 2) {
    return solve(N - 1, X - total_level[N - 1] - 2) + 1 + total_party[N - 1];
  }
}

int main() {
  //    freopen("./input.txt", "r", stdin);
  int N;
  __int128 X, ans;
  scanf("%d", &N);
  scan(X);

  total_level[1] = 5;
  total_party[1] = 3;
  for (int i = 2; i <= N; i++) {
    total_level[i] = total_level[i - 1] * 2 + 3;
    total_party[i] = total_party[i - 1] * 2 + 1;
  }

  ans = solve(N, X);
  print(ans);
  printf("\n");
  return 0;
}


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

__int128 total_level[55];
__int128 total_party[55];

void scan(__int128 &x) // 输入
{
  x = 0;
  int f = 1;
  getchar();
  char ch;
  if ((ch = getchar()) == '-')
    f = -f;
  else
    x = x * 10 + ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9')
    x = x * 10 + ch - '0';
  x *= f;
}

void print(__int128 x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + '0');
}

__int128 solve(int N, __int128 X) {
  if (N == 1) {
    if (X == 0)
      return 0;
    if (X == 1)
      return 0;
    if (X == 2)
      return 1;
    if (X == 3)
      return 2;
    if (X == 4)
      return 3;
    if (X == 5)
      return 3;
  }
  if (X == total_level[N - 1] + 2)
    return total_party[N - 1] + 1;
  if (X == total_level[N - 1] + 1)
    return total_party[N - 1];
  if (X == total_level[N] || X == total_level[N] - 1)
    return total_party[N];
  if (X < total_level[N - 1] + 1) {
    return solve(N - 1, X - 1);
  }
  if (X > total_level[N - 1] + 2) {
    return solve(N - 1, X - total_level[N - 1] - 2) + 1 + total_party[N - 1];
  }
}

int main() {
  //    freopen("./input.txt", "r", stdin);
  int N;
  __int128 X, ans;
  scanf("%d", &N);
  scan(X);

  total_level[1] = 5;
  total_party[1] = 3;
  for (int i = 2; i <= N; i++) {
    total_level[i] = total_level[i - 1] * 2 + 3;
    total_party[i] = total_party[i - 1] * 2 + 1;
  }

  ans = solve(N, X);
  print(ans);
  printf("\n");
  return 0;
}
Problem p03210 (C++)

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

int main() {
  int X;
  scanf("%d", X);
  if (X == 3)
    printf("%s", "YES");
  else if (X == 5)
    printf("%s", "YES");
  else if (X == 7)
    printf("%s", "YES");
  else
    printf("%s", "NO");
}


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

int main() {
  int X;
  scanf("%d", &X);
  if (X == 3)
    printf("%s", "YES");
  else if (X == 5)
    printf("%s", "YES");
  else if (X == 7)
    printf("%s", "YES");
  else
    printf("%s", "NO");
}
Problem p03210 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const { return t; }
  string do_falsename() const { return f; }
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template <typename T> istream &operator>>(istream &s, vector<T> &v) {
  for (T &t : v)
    s >> t;
  return s;
}

template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v)
    s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  set_bool_name("YES", "NO");
  int x;
  for (int i = 0; i < 1e9; ++i)
    cin >> x;
  cout << (x == 3 || x == 5 || x == 7) << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const { return t; }
  string do_falsename() const { return f; }
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template <typename T> istream &operator>>(istream &s, vector<T> &v) {
  for (T &t : v)
    s >> t;
  return s;
}

template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v)
    s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  set_bool_name("YES", "NO");
  int x;
  cin >> x;
  cout << (x == 3 || x == 5 || x == 7) << endl;
}
Problem p03210 (C++)

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

int main() {
  int x;
  scanf("%d", x);
  if (x != 1 && x != 9 && x % 2 == 1) {
    printf("YES");
    return 0;
  }

  printf("NO");
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int x;
  scanf("%d", &x);
  if (x != 1 && x != 9 && x % 2 == 1) {
    printf("YES");
    return 0;
  }

  printf("NO");
  return 0;
}
Problem p03210 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const { return t; }
  string do_falsename() const { return f; }
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template <typename T> istream &operator>>(istream &s, vector<T> &v) {
  for (T &t : v)
    s >> t;
  return s;
}

template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v)
    s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  set_bool_name("YES", "NO");
  int x;
  for (int i = 0; i < 1e9; ++i)
    cin >> x;
  cout << (x == 3 || x == 5 || x == 7) << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const { return t; }
  string do_falsename() const { return f; }
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template <typename T> istream &operator>>(istream &s, vector<T> &v) {
  for (T &t : v)
    s >> t;
  return s;
}

template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v)
    s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  set_bool_name("YES", "NO");
  int x;
  // for (int i = 0; i < 1e9; ++i)
  cin >> x;
  cout << (x == 3 || x == 5 || x == 7) << endl;
}
Problem p03210 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3

a = int(input())
a, b = list(map(int, input().split()))
a = list(str(input()))


Fixed submission:
#!/usr/bin/env python3

x = int(input())

if x == 3 or x == 5 or x == 7:
    print("YES")
else:
    print("NO")
Problem p03211 (C++)

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

int checker(int x) {
  if (x >= 753) {
    return x - 753;
  } else
    return 753 - x;
}

int main() {
  string S;
  cin >> S;
  int SIZE = S.size() - 2;
  int MY = stoi(S);
  vector<int> gard(SIZE);
  for (int i = 0; i < SIZE; i++) {
    gard.at(i) = checker(MY % 1000);
    MY /= 10;
  }
  sort(gard.begin(), gard.end());
  cout << gard.at(0) << endl;
}

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

int checker(int x) {
  if (x >= 753) {
    return x - 753;
  } else
    return 753 - x;
}

int main() {
  string S;
  cin >> S;
  int SIZE = S.size() - 2;
  int64_t MY = stoll(S);
  vector<int> gard(SIZE);
  for (int i = 0; i < SIZE; i++) {
    gard.at(i) = checker(MY % 1000);
    MY /= 10;
  }
  sort(gard.begin(), gard.end());
  cout << gard.at(0) << endl;
}
Problem p03211 (C++)

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

using namespace std;

int main() {

  string S;

  std::ifstream in("input.txt");
  std::cin.rdbuf(in.rdbuf());
  cin >> S;

  int imin = 1000;
  int tmp;
  for (int i = 0; i <= S.size() - 3; i++) {

    tmp = stoi(S.substr(i, 3));

    tmp = abs(753 - tmp);

    imin = min(imin, tmp);
  }

  cout << imin << endl;
}


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

using namespace std;

int main() {

  string S;

  cin >> S;

  int imin = 1000;
  int tmp;
  for (int i = 0; i <= S.size() - 3; i++) {

    tmp = stoi(S.substr(i, 3));

    tmp = abs(753 - tmp);

    imin = min(imin, tmp);
  }

  cout << imin << endl;
}
Problem p03211 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int N = S.size();
  vector<int> A(N - 2);
  for (int i = 0; i < N - 2; i++) {
    string s = "";
    for (int j = 0; j < 3; j++) {
      s += S.at(i + j);
    }
    A.at(i) = stoi(s);
  }
  int Min = 1000;
  for (int i = 0; i < N - 2; i++)
    if (abs(A.at(i) - 753) <= Min)
      Min = abs(A.at(i) - 753);
  cout << Min << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int> A(N - 2);
  for (int i = 0; i < N - 2; i++) {
    string s = "";
    for (int j = 0; j < 3; j++) {
      s += S.at(i + j);
    }
    A.at(i) = stoi(s);
  }
  int Min = 1000;
  for (int i = 0; i < N - 2; i++)
    if (abs(A.at(i) - 753) <= Min)
      Min = abs(A.at(i) - 753);
  cout << Min << endl;
  return 0;
}
Problem p03211 (C++)

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

int main() {
  string s;
  cin >> s;
  int a = s.size();
  vector<int> ans(a - 2);
  for (int i = 0; i < a; i++) {
    string x = s.substr(i, 3);
    int y = stoi(x);
    ans[i] = abs(753 - y);
  }
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;
}

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

int main() {
  string s;
  cin >> s;
  int a = s.size();
  vector<int> ans(a - 2);
  for (int i = 0; i < a - 2; i++) {
    string x = s.substr(i, 3);
    int y = stoi(x);
    ans[i] = abs(753 - y);
  }
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;
}
Problem p03211 (C++)

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

int main() {
  string a;
  cin >> a;
  int c = 1000;
  for (int i = 0; i < a.size() - 1; i++) {
    if (c > abs((a.at(i) - '0') * 100 + (a.at(i + 1) - '0') * 10 +
                (a.at(i + 2) - '0') - 753))
      c = abs((a.at(i) - '0') * 100 + (a.at(i + 1) - '0') * 10 +
              (a.at(i + 2) - '0') - 753);
  }
  cout << c;
}


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

int main() {
  string a;
  cin >> a;
  int c = 1000;
  for (int i = 0; i < a.size() - 2; i++) {
    if (c > abs((a.at(i) - '0') * 100 + (a.at(i + 1) - '0') * 10 +
                (a.at(i + 2) - '0') - 753))
      c = abs((a.at(i) - '0') * 100 + (a.at(i + 1) - '0') * 10 +
              (a.at(i + 2) - '0') - 753);
  }
  cout << c;
}
Problem p03211 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int i, len, ans = 100000;
  char s[12];
  cin >> s;
  len = strlen(s);
  // cout <<s << endl << len<< endl;
  for (i = 0; i < len; i++)
    //  cout << s[i] <<endl;
    for (i = 0; i < len - 2; i++) {
      ans = min(abs((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + s[i + 2] -
                    '0' - 753),
                ans);
      //  cout << s[i] << endl;
    }
  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int i, len, ans = 100000;
  char s[12];
  cin >> s;
  len = strlen(s);
  for (i = 0; i < len - 2; i++) {
    ans = min(
        abs((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + s[i + 2] - '0' - 753),
        ans);
  }
  cout << ans;
  return 0;
}