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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
    sum += x;
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < k; i++) {
    sum -= v[i];
  }
  cout << sum << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
    sum += x;
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < v.size(); i++) {
    if (i >= k)
      break;
    sum -= v[i];
  }
  cout << sum << "\n";
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const int N = 1e5 + 10;
ll a[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif

  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  ll ans = 0;
  for (int i = k + 1; i <= n; i++) {
    ans += a[i];
  }
  cout << ans << "\n";

#ifdef LOCAL
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const int N = 2e5 + 10;
ll a[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif

  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  ll ans = 0;
  for (int i = k + 1; i <= n; i++) {
    ans += a[i];
  }
  cout << ans << "\n";

#ifdef LOCAL
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}
Problem p02785 (C++)

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

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repr(i, n) for (int(i) = (n); (i) > 0; (i)--)
#define rrep(i, n, m) for (int(i) = (n); (i) < (m); (i)++)
#define rrepr(i, n, m) for (int(i) = (n); (i) > (m); (i)--)
#define SORT(s) sort((s).begin(), (s).end())
#define SORTR(s, t) sort((s).begin(), (s).end(), greater<t>())

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX = 510000;

int N, K;
vll H;
void input() {
  cin >> N >> K;
  rep(i, N) {
    ll a;
    cin >> a;
    H.emplace_back(a);
  }
  return;
}

void solve() {
  SORTR(H, ll);
  rep(i, K) H[i] = 0ll;
  ll ans = 0ll;
  rep(i, N) ans += H[i];
  cout << ans << endl;
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  input();
  solve();
  return 0;
}

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

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repr(i, n) for (int(i) = (n); (i) > 0; (i)--)
#define rrep(i, n, m) for (int(i) = (n); (i) < (m); (i)++)
#define rrepr(i, n, m) for (int(i) = (n); (i) > (m); (i)--)
#define SORT(s) sort((s).begin(), (s).end())
#define SORTR(s, t) sort((s).begin(), (s).end(), greater<t>())

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX = 510000;

int N, K;
vll H;
void input() {
  cin >> N >> K;
  rep(i, N) {
    ll a;
    cin >> a;
    H.emplace_back(a);
  }
  return;
}

void solve() {
  SORTR(H, ll);
  rep(i, min(N, K)) H[i] = 0ll;
  ll ans = 0ll;
  rep(i, N) ans += H[i];
  cout << ans << endl;
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  input();
  solve();
  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, k, h[100010];
  long long ans = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> h[i];
  sort(h, h + n);
  for (int i = 0; i < n - k; i++) {
    ans += h[i];
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, k, h[200010];
  long long ans = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> h[i];
  sort(h, h + n);
  for (int i = 0; i < n - k; i++) {
    ans += h[i];
  }
  cout << ans;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#define re register
using namespace std;
typedef long long ll;

inline int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    X = X * 10 + c - '0', c = getchar();
  return X * w;
}

int a[100010];

int main() {
  int n = read(), k = min(n, read());
  for (re int i = 1; i <= n; ++i)
    a[i] = read();
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  ll ans = 0;
  for (re int i = k + 1; i <= n; ++i)
    ans += a[i];
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#define re register
using namespace std;
typedef long long ll;

inline int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    X = X * 10 + c - '0', c = getchar();
  return X * w;
}

int a[200010];

int main() {
  int n = read(), k = min(n, read());
  for (re int i = 1; i <= n; ++i)
    a[i] = read();
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  ll ans = 0;
  for (re int i = k + 1; i <= n; ++i)
    ans += a[i];
  printf("%lld\n", ans);
  return 0;
}
Problem p02785 (C++)

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

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

  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end());
  rep(i, k) h.pop_back();

  long long ans = 0;
  rep(i, h.size()) ans += h[i];
  cout << ans << '\n';

  return 0;
}

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

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

  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end());
  if (n > k)
    rep(i, k) h.pop_back();
  else {
    cout << 0 << '\n';
    return 0;
  }

  long long ans = 0;
  rep(i, h.size()) ans += h[i];
  cout << ans << '\n';

  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vc = vector<char>;
using vb = vector<bool>;
using vl = vector<ll>;
#define rep(i, x, n) for (int i = x; i < n; i++)
#define all(x) x.begin(), x.end()

int main() {
  ll n, k, sum = 0;
  cin >> n >> k;
  vl h(n);
  rep(i, 0, n) { cin >> h[i]; }
  sort(h.begin(), h.end());
  for (int i = 0; i < k; i++) {
    h[n - 1 - i] = 0;
  }
  for (int i = 0; i < n; i++) {
    sum += h[i];
  }
  cout << sum;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vc = vector<char>;
using vb = vector<bool>;
using vl = vector<ll>;
#define rep(i, x, n) for (int i = x; i < n; i++)
#define all(x) x.begin(), x.end()

int main() {
  ll n, k, sum = 0;
  cin >> n >> k;
  vl h(n);
  rep(i, 0, n) { cin >> h[i]; }
  sort(h.begin(), h.end());
  for (int i = 0; i < k && i < n; i++) {
    h[n - 1 - i] = 0;
  }
  for (int i = 0; i < n; i++) {
    sum += h[i];
  }
  cout << sum;
}
Problem p02785 (C++)

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

typedef long long LL;

const int N = 100000;

int n, m, a[N + 9];
LL ans;

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = n - m; i >= 1; --i)
    ans += a[i];
  printf("%lld\n", ans);
  return 0;
}

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

typedef long long LL;

const int N = 200000;

int n, m, a[N + 9];
LL ans;

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = n - m; i >= 1; --i)
    ans += a[i];
  printf("%lld\n", ans);
  return 0;
}
Problem p02785 (C++)

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

  int N, K;
  long T = 0;
  cin >> N >> K;

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

  if (N < K)
    K = N;

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

  for (int i = 0; i < N - K; i++) {
    T += H.at(i);
  }

  cout << T << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {

  int N, K;
  long T = 0;
  cin >> N >> K;

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

  if (N < K)
    K = N;

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

  for (int i = 0; i < N - K; i++) {
    T += H.at(i);
  }

  cout << T << endl;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;

void solve() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) { cin >> h[i]; }
  sort(h.begin(), h.end(), greater<int>());
  rep(i, k) { h[i] = 0; }
  ll sum = 0;
  rep(i, n) sum += h[i];
  cout << sum;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;

void solve() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) { cin >> h[i]; }
  sort(h.begin(), h.end(), greater<int>());

  rep(i, min(n, k)) { h[i] = 0; }
  ll sum = 0;
  rep(i, n) sum += h[i];
  cout << sum;

  return 0;
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  long long N, K;
  cin >> N >> K;
  vector<long long> vec(N);
  for (int i = 0; i < N; ++i)
    cin >> vec[i];
  sort(vec.begin(), vec.end(), greater<int>());
  for (int i = 0; i < K; ++i) {
    vec[i] = 0;
  }
  long long tmp = 0;
  for (auto i : vec)
    tmp += i;
  cout << tmp << "\n";
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  long long N, K;
  cin >> N >> K;
  vector<long long> vec(N);
  for (int i = 0; i < N; ++i)
    cin >> vec[i];
  sort(vec.begin(), vec.end(), greater<int>());
  for (int i = 0; i < K; ++i) {
    if (i >= N)
      break;
    vec[i] = 0;
  }
  long long tmp = 0;
  for (auto i : vec)
    tmp += i;
  cout << tmp << "\n";
}
Problem p02785 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int a[200000];
int main() {
  int n, k, M = -1, ti, i;
  long long s = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  sort(a, a + n);
  for (i = 1; i <= k; i++)
    s -= a[n - i];
  cout << s;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int a[200000];
int main() {
  int n, k, M = -1, ti, i;
  long long s = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  if (n <= k) {
    cout << "0";
    return 0;
  }
  sort(a, a + n);
  for (i = 1; i <= k; i++)
    s -= a[n - i];
  cout << s;
  return 0;
}
Problem p02786 (C++)

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

int main() {
  int64_t h = 0, c = 1;
  cin >> h;

  cout << flush;
  if (h <= 1)
    return 1;

  while (h > 1) {
    h /= 2;
    ++c;
  }

  int64_t ans = 0, d = 1;

  for (int i = 0; i < c; ++i) {
    ans += d;
    d *= 2;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int64_t h = 0, c = 1;
  cin >> h;

  while (h > 1) {
    h /= 2;
    ++c;
  }

  int64_t ans = 0, d = 1;

  for (int i = 0; i < c; ++i) {
    ans += d;
    d *= 2;
  }

  cout << ans << endl;

  return 0;
}
Problem p02786 (C++)

Buggy submission (status: Runtime Error):
/*    FAILING IS AN ART
       AND
     I HAVE MASTERED IT
*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
#define ld long double
using namespace std;

ll bin_exp(ll a, ll b) {
  ll ans = 1;
  if (a == 0)
    ans = 1;

  while (b > 0) {
    if (b & 1)
      ans *= a;

    a *= a;
    b >>= 1;
  }
  return ans;
}

ll fun(ll x) {
  if (x == 1)
    return 1;
  if (x % 2)
    x--;
  return 1 + 2 * fun(x / 2);
}

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast;

  ll h;
  cin >> h;

  if (h == 1) {
    cout << 1 << endl;
    return 0;
  }

  else if (h == 2 or h == 3) {
    cout << 3 << endl;
  }

  else {
    cout << fun(h) << endl;
  }
}

Fixed submission:
/*    FAILING IS AN ART
       AND
     I HAVE MASTERED IT
*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
#define ld long double
using namespace std;

ll bin_exp(ll a, ll b) {
  ll ans = 1;
  if (a == 0)
    ans = 1;

  while (b > 0) {
    if (b & 1)
      ans *= a;

    a *= a;
    b >>= 1;
  }
  return ans;
}

ll fun(ll x) {
  if (x == 1)
    return 1;
  if (x % 2)
    x--;
  return 1 + 2 * fun(x / 2);
}

int main() {

  fast;

  ll h;
  cin >> h;

  if (h == 1) {
    cout << 1 << endl;
    return 0;
  }

  else if (h == 2 or h == 3) {
    cout << 3 << endl;
  }

  else {
    cout << fun(h) << endl;
  }
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
int minimumCost(int price[], int n) {
  sort(price, price + n);
  int totalCost = 0;
  for (int i = n - 1; i > 1; i -= 2) {
    if (i == 2) {
      totalCost += price[2] + price[0];
    } else {
      int price_first = price[i] + price[0] + 2 * price[1];
      int price_second = price[i] + price[i - 1] + 2 * price[0];
      totalCost += min(price_first, price_second);
    }
  }
  if (n == 1) {
    totalCost += price[0];
  } else {
    totalCost += price[1];
  }

  return totalCost;
}
int func(int a) { return 1 + 2 * func(a / 2); }
int32_t main() {
  int h;
  cin >> h;
  cout << func(h);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int minimumCost(int price[], int n) {
  sort(price, price + n);
  int totalCost = 0;
  for (int i = n - 1; i > 1; i -= 2) {
    if (i == 2) {
      totalCost += price[2] + price[0];
    } else {
      int price_first = price[i] + price[0] + 2 * price[1];
      int price_second = price[i] + price[i - 1] + 2 * price[0];
      totalCost += min(price_first, price_second);
    }
  }
  if (n == 1) {
    totalCost += price[0];
  } else {
    totalCost += price[1];
  }

  return totalCost;
}
int func(int a) {
  if (a == 0)
    return 0;
  return 1 + 2 * func(a / 2);
}
int32_t main() {
  int h;
  cin >> h;
  cout << func(h);
  return 0;
}
Problem p02786 (C++)

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

ll const mod = (ll)1e12;
#define max 1000

ll mons(ll h) {
  int i = 1;
  ll ans = 0;
  while (i <= h) {
    ans += i;
    i = i * 2;
  }
  return ans;
}
int main() {
  ll h;
  cin >> h;
  ll ans = mons(h);
  cout << ans;
  return 0;
}

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

ll const mod = (ll)1e12;
#define max 1000

ll mons(ll h) {
  ll i = 1;
  ll ans = 0;
  while (i <= h) {
    ans += i;
    i = i * 2;
  }
  return ans;
}
int main() {
  ll h;
  cin >> h;
  ll ans = mons(h);
  cout << ans;
  return 0;
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

int main() {
  ll H;
  cin >> H;
  queue<ll> q;
  q.push(H);

  ll s = 0LL;
  while (!q.empty()) {
    ll h = q.front();
    q.pop();
    s += 1;
    if (h > 1) {
      q.push(h / 2);
      q.push(h / 2);
    }
  }
  cout << s << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

int main() {
  ll H;
  cin >> H;
  ll i = 0LL, s = 0LL;
  while (H > 0LL) {
    s += pow(2LL, i++);
    H = H / 2LL;
  }
  cout << s << endl;
  return 0;
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define all(vv) (vv).begin(), (vv).end()
#define rep(ii, jj, ll, ss) for (int ii = jj; ii < ll; ii += ss)
#define time                                                                   \
  cerr << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';                    \
  return 0;

int h, ans;
int foo(int n) {
  if (n == 1)
    return 1;
  return 1 + foo(n / 2) + foo(n / 2);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> h;
  ans = foo(h);
  cout << ans;
  time
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define all(vv) (vv).begin(), (vv).end()
#define rep(ii, jj, ll, ss) for (int ii = jj; ii < ll; ii += ss)
#define time                                                                   \
  cerr << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';                    \
  return 0;

int h, ans;
int foo(int n) {
  if (n == 1)
    return 1;
  return 1 + 2 * foo(n / 2);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> h;
  ans = foo(h);
  cout << ans;
  time
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <algorithm>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <vector>
typedef long long int ll;
typedef double ld;
using namespace std;

class DCaracalVsMonster {
public:
  void solve(std::istream &in, std::ostream &out) {
    ll n, i, step = 0;
    in >> n;

    for (i = 0;; i++) {
      ll po = 1 << i;
      if (po > n) {
        break;
      }
      if (po <= n) {
        step += po;
      }
    }
    out << step << endl;
  }
};

int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  DCaracalVsMonster solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Fixed submission:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <algorithm>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <vector>
typedef long long int ll;
typedef double ld;
using namespace std;

class DCaracalVsMonster {
public:
  void solve(std::istream &in, std::ostream &out) {
    ll n, i, step = 0;
    in >> n;

    for (i = 0;; i++) {
      ll po = 1LL << i;
      if (po > n) {
        break;
      }
      if (po <= n) {
        step += po;
      }
    }
    out << step << endl;
  }
};

int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  DCaracalVsMonster solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}
Problem p02786 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
#define MOD 1000000007
#define debug(x) cout << "x :" << x << endl;
#define case(t, ans) cout << "Case #" << t << ": " << ans << endl;
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
// typedef long long ll;
// typedef vector<int> vi;
// typedef pair<int,int> pi;

using namespace std;

void solve();
ll cal(ll n) {
  if (n == 1)
    return 1;
  return (2 * cal(n / 2) + 1);
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  //  int t;
  //  cin>>t;
  // while(t--)
  solve();

  return 0;
}

void solve() {
  ll h;
  cin >> h;

  cout << cal(h) << endl;
}


Fixed submission:

#include <bits/stdc++.h>
#define MOD 1000000007
#define debug(x) cout << "x :" << x << endl;
#define case(t, ans) cout << "Case #" << t << ": " << ans << endl;
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
// typedef long long ll;
// typedef vector<int> vi;
// typedef pair<int,int> pi;

using namespace std;

void solve();
ll cal(ll n) {
  if (n == 1)
    return 1;
  return (2 * cal(n / 2) + 1);
}
int main() {
  //  #ifndef ONLINE_JUDGE
  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
  //  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  //  int t;
  //  cin>>t;
  // while(t--)
  solve();

  return 0;
}

void solve() {
  ll h;
  cin >> h;

  cout << cal(h) << endl;
}
Problem p02786 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
using namespace std;

template <typename T> inline string to_bin_str(T n) {
  string str;
  while (n > 0) {
    str.push_back('0' + (n & 1));
    n >>= 1;
  }
  reverse(str.begin(), str.end());
  return str;
}

int main() {

  long long H;
  cin >> H;

  string bin = to_bin_str(H);
  for (int i = 0; i < bin.length(); i++) {
    if (bin[i] == '0') {
      bin[i] = '1';
    }
  }

  int ans = stoi(bin, 0, 2);

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
using namespace std;

template <typename T> inline string to_bin_str(T n) {
  string str;
  while (n > 0) {
    str.push_back('0' + (n & 1));
    n >>= 1;
  }
  reverse(str.begin(), str.end());
  return str;
}

int main() {

  long long H;
  cin >> H;

  string bin = to_bin_str(H);
  for (int i = 0; i < bin.length(); i++) {
    if (bin[i] == '0') {
      bin[i] = '1';
    }
  }

  long long ans = stol(bin, 0, 2);

  cout << ans << endl;
  return 0;
}
Problem p02786 (C++)

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

int64_t attack(int64_t hp) {
  if (hp == 1) {
    return 1;
  }
  return 1 + attack(hp / 2) + attack(hp / 2);
}

int main() {
  int64_t h, min;
  cin >> h;
  min = attack(h);
  cout << min << endl;
}

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

int64_t attack(int64_t hp) {
  if (hp == 1) {
    return 1;
  }
  return 1 + 2 * attack(hp / 2);
}

int main() {
  int64_t h, min;
  cin >> h;
  min = attack(h);
  cout << min << endl;
}
Problem p02786 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long h;

int fun(long long v) {
  int ret = 2 * fun(v / 2);
  if (v % 2)
    ret++;
  return ret;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> h;
  cout << fun(h) << E;
  // system("pause");
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long h;

long long fun(long long v) {
  if (v == 1)
    return 1;
  long long ret = 2 * fun(v / 2);
  ret++;
  return ret;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> h;
  cout << fun(h) << E;
  // system("pause");
  return 0;
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i <= int(b); ++i)
using namespace std;
template <class A> void pr(A a) { cout << (a) << endl; }
template <class A, class B> void pr(A a, B b) {
  cout << a << " ";
  pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
  cout << a << " ";
  pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
  cout << a << " ";
  pr(b, c, d);
}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF = numeric_limits<int>::max();
// for(int j=0;j<N;++j) {
ll atack_cnt(ll H) {
  if (H < 2) {
    return 1;
  }
  return atack_cnt(H / 2) + atack_cnt(H / 2) + 1;
}

int main(void) {
  ll H;
  cin >> H;
  // ll res=0;
  pr(atack_cnt(H));
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i <= int(b); ++i)
using namespace std;
template <class A> void pr(A a) { cout << (a) << endl; }
template <class A, class B> void pr(A a, B b) {
  cout << a << " ";
  pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
  cout << a << " ";
  pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
  cout << a << " ";
  pr(b, c, d);
}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF = numeric_limits<int>::max();
// for(int j=0;j<N;++j) {
ll atack_cnt(ll H) {
  if (H < 2) {
    return 1;
  }
  return atack_cnt(H / 2) * 2 + 1;
}

int main(void) {
  ll H;
  cin >> H;
  // ll res=0;
  pr(atack_cnt(H));
  return 0;
}
Problem p02786 (C++)

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

long long func(long long H) {
  if (H == 1)
    return 1;
  else {
    return func(2 / H) + 1;
  }
}

int main(void) {
  long long H;

  cin >> H;

  cout << func(H) << endl;

  return 0;
}

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

long long func(long long H) {
  if (H == 1)
    return 1;
  else {
    return 2 * func(H / 2) + 1;
  }
}

int main(void) {
  long long H;

  cin >> H;

  cout << func(H) << endl;

  return 0;
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "math.h"
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <typeinfo>
#include <vector>

#define pai 3.14159265358979323846264338327950288
using namespace std;

// Caracal vs Monster

int main() {

  long long int h, cnt = 0, sum = 0;
  cin >> h;

  while (true) {
    h /= 2;
    sum += pow(2, cnt);
    cnt++;
    if (h == 1) {
      sum += pow(2, cnt);
      break;
    }
  }

  cout << sum;

  return 0;
}


Fixed submission:
#include "math.h"
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <typeinfo>
#include <vector>

#define pai 3.14159265358979323846264338327950288
using namespace std;

// Caracal vs Monster

int main() {

  long long int h, cnt = 0, sum = 0;
  cin >> h;

  while (true) {
    if (h == 1) {
      sum = 1;
      break;
    }
    h /= 2;
    sum += pow(2, cnt);
    cnt++;
    if (h == 1) {
      sum += pow(2, cnt);
      break;
    }
  }

  cout << sum;

  return 0;
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORN(i, b, a) for (int i = (b); _a = (a); i >= _a; i--)
#define REP(i, n) for (int i = 0, _n = n; i < n; i++)
#define ll long long
#define pii pair<int, int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define size(s) s.size()
using namespace std;
inline void read(int &x) {
  short negative = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      negative = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  x *= negative;
}
ll dg(ll n) {
  if (n == 1)
    return 1;
  else
    return dg(n / 2) + dg(n / 2) + 1;
}
int main() {
  ll n;
  cin >> n;
  cout << dg(n) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORN(i, b, a) for (int i = (b); _a = (a); i >= _a; i--)
#define REP(i, n) for (int i = 0, _n = n; i < n; i++)
#define ll long long
#define pii pair<int, int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define size(s) s.size()
using namespace std;
inline void read(int &x) {
  short negative = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      negative = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  x *= negative;
}
ll dg(ll n) {
  if (n == 1)
    return 1;
  else
    return dg(n / 2) * 2 + 1;
}
int main() {
  ll n;
  cin >> n;
  cout << dg(n) << endl;
  return 0;
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX / 10
#define rep(i, n) for (int i = 0; i < n; i++)
#define krep(i, k, n, m) for (int i = k; i < n; i += m)
#define erep(i, k, n) for (int i = k; i < n; i++)
#define mod 1000000007
// 最大公約数
int gcd(int s, int b) {
  if (b == 0)
    return s;
  return gcd(b, s % b);
}
signed main() {
  int n;
  cin >> n;
  int w = 1, ans = 0;
  while (1) {
    ans += w;
    w = w * 2;
    n = n / 2;
    if (n == 1) {
      break;
    }
  }
  cout << ans + w << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX / 10
#define rep(i, n) for (int i = 0; i < n; i++)
#define krep(i, k, n, m) for (int i = k; i < n; i += m)
#define erep(i, k, n) for (int i = k; i < n; i++)
#define mod 1000000007
// 最大公約数
int gcd(int s, int b) {
  if (b == 0)
    return s;
  return gcd(b, s % b);
}
signed main() {
  int n;
  cin >> n;
  int w = 1, ans = 0;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  while (1) {
    ans += w;
    w = w * 2;
    n = n / 2;
    if (n == 1) {
      break;
    }
  }
  cout << ans + w << endl;
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long solve(long long x) { return 2 * solve(x / 2) + 1; }
int main() {
  long long h;
  cin >> h;
  cout << solve(h) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long solve(long long x) {
  if (x)
    return 2 * solve(x / 2) + 1;
  else
    return 0;
}
int main() {
  long long h;
  cin >> h;
  cout << solve(h) << endl;
}
Problem p02786 (C++)

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

long long dfs(long long a) {
  if (a == 1)
    return 2;
  return (dfs(a / 2) + 1) * 2;
}

int main() {
  long long h;
  cin >> h;
  cout << dfs(h / 2) + 1;
}

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

long long dfs(long long a) {
  if (a == 1)
    return 2;
  return (dfs(a / 2) + 1) * 2;
}

int main() {
  long long h;
  cin >> h;
  if (h == 1)
    cout << 1;
  else
    cout << dfs(h / 2) + 1;
}
Problem p02786 (C++)

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

#define int long long
#define ll long long
#define f1(i, a, b) for (int i = a; i < b; i++)
#define f2(i, a, b) for (int i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod = 1000000007;
ll temp;

int solve(int h) {
  if (h == 1)
    return 1;

  return solve(h / 2) + solve(h / 2) + 1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  // #ifndef ONLINE_JUDGE
  // 	freopen("/home/akmittal/Desktop/Competitive
  // Programming/in.txt","r",stdin); 	freopen("/home/akmittal/Desktop/Competitive
  // Programming/out.txt","w",stdout); #endif

  int h;
  cin >> h;

  cout << solve(h);

  return 0;
}

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

#define int long long
#define ll long long
#define f1(i, a, b) for (int i = a; i < b; i++)
#define f2(i, a, b) for (int i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod = 1000000007;
ll temp;

int solve(int h) {
  if (h == 1)
    return 1;

  return 2 * solve(h / 2) + 1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  // #ifndef ONLINE_JUDGE
  // 	freopen("/home/akmittal/Desktop/Competitive
  // Programming/in.txt","r",stdin); 	freopen("/home/akmittal/Desktop/Competitive
  // Programming/out.txt","w",stdout); #endif

  int h;
  cin >> h;

  cout << solve(h);

  return 0;
}
Problem p02786 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 2147483647
#define int long long
#define _MATH_DEFINES_DEFINED
#pragma GCC optimize("O2")
using namespace std;
int tot, cs;
inline int read(void) {
  int f = 1, n = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    n = n * 10 + (c - '0');
    c = getchar();
  }
  return f * n;
}
void step(int h) {
  if (h == 1)
    tot += cs;
  else
    step(h >> 1), tot += cs;
  cs *= 2;
  return;
}
signed main(void) {
  int h = read();
  tot++, cs = 2;
  step(h >> 1);
  cout << tot << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define INF 2147483647
#define int long long
#define _MATH_DEFINES_DEFINED
#pragma GCC optimize("O2")
using namespace std;
int tot, cs;
inline int read(void) {
  int f = 1, n = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    n = n * 10 + (c - '0');
    c = getchar();
  }
  return f * n;
}
void step(int h) {
  if (h == 1)
    tot += cs;
  else
    step(h >> 1), tot += cs;
  cs *= 2;
  return;
}
signed main(void) {
  int h = read();
  if (h == 1) {
    cout << 1 << endl;
    return 0;
  }
  tot++, cs = 2;
  step(h >> 1);
  cout << tot << endl;
  return 0;
}
Problem p02786 (C++)

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

using ll = long long;

ll func(ll n) {
  if (n == 1)
    return 1;
  return 2 * func(n / 2) + 1;
}

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll h;
  cin >> h;
  ll ans = func(h);
  cout << ans;
  return 0;
}

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

using ll = long long;

ll func(ll n) {
  if (n == 1)
    return 1;
  return 2 * func(n / 2) + 1;
}

int main() {

#ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll h;
  cin >> h;
  ll ans = func(h);
  cout << ans;
  return 0;
}
Problem p02786 (C++)

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

int64_t times2(int64_t n) {
  int64_t output = 1;
  for (int64_t i = 0; i < n; ++i) {
    output *= 2;
  }
  return output;
}

int main() {
  // input
  int64_t H;
  cin >> H;

  // calculation
  int64_t count = 1;
  while (1) {
    H /= 2;
    count++;
    if (H == 1) {
      break;
    }
  }
  int64_t output = times2(count) - 1;

  // output
  cout << output << endl;

  return 0;
}


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

int64_t times2(int64_t n) {
  int64_t output = 1;
  for (int64_t i = 0; i < n; ++i) {
    output *= 2;
  }
  return output;
}

int main() {
  // input
  int64_t H;
  cin >> H;

  // calculation
  if (H == 1) {
    cout << 1 << endl;
    return 0;
  }

  int64_t count = 1;
  while (1) {
    H /= 2;
    count++;
    if (H == 1) {
      break;
    }
  }
  int64_t output = times2(count) - 1;

  // output
  cout << output << endl;

  return 0;
}
Problem p02786 (C++)

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

int main() {
  long long h, a, b, c, i, j, k, n, m, x, y, ans = 0;
  string str;

  cin >> h;

  c = 1;
  while (1) {
    ans += c;
    c = c * 2;
    h = h / 2;
    if (h == 1) {
      ans += c;
      break;
    }
  }
  cout << ans << endl;
}


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

int main() {
  long long h, a, b, c, i, j, k, n, m, x, y, ans = 0;
  string str;

  cin >> h;

  if (h == 1) {
    cout << 1 << endl;
    return 0;
  }
  c = 1;
  while (1) {
    ans += c;
    c = c * 2;
    h = h / 2;
    if (h == 1) {
      ans += c;
      break;
    }
  }
  cout << ans << endl;
}
Problem p02786 (C++)

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

typedef long long ll;
const int N = 2e5;
ll arr[N + 5];

int main() {
  ll total = 0;
  ll n;
  cin >> n;
  ll cur = 1;
  while (n) {
    if (n == 1)
      total += cur;
    else {
      total += cur;
      n /= 2;
      cur *= 2;
    }
  }
  cout << total << endl;
}

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

typedef long long ll;
const int N = 2e5;
ll arr[N + 5];

int main() {
  ll total = 0;
  ll n;
  cin >> n;
  ll cur = 1;
  while (n) {
    total += cur;
    n /= 2;
    cur *= 2;
  }
  cout << total << endl;
}
Problem p02786 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(
                chrono::high_resolution_clock::now().time_since_epoch())
                .count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N = 400015;
#define M 1000000007
#define double long double
#define BINF 100000000000000
#define init(arr, val) memset(arr, val, sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;

map<int, int> lol;

#undef int
int main() {
#define int long long int
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("ip.txt", "r", stdin);
  freopen("op1.txt", "w", stdout);
#endif

  int n;
  cin >> n;
  int ans = 0;
  while (n > 0) {
    if (lol[n] == 0) {
      ans++;
      lol[n / 2] += 2;
    } else {
      ans += lol[n];
      lol[n / 2] += 2 * lol[n];
    }
    n /= 2;
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(
                chrono::high_resolution_clock::now().time_since_epoch())
                .count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N = 400015;
#define M 1000000007
#define double long double
#define BINF 100000000000000
#define init(arr, val) memset(arr, val, sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;

map<int, int> lol;

#undef int
int main() {
#define int long long int
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;
  int ans = 0;
  while (n > 0) {
    if (lol[n] == 0) {
      ans++;
      lol[n / 2] += 2;
    } else {
      ans += lol[n];
      lol[n / 2] += 2 * lol[n];
    }
    n /= 2;
  }
  cout << ans << endl;

  return 0;
}
Problem p02786 (C++)

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

int main() {
  long long H;
  cin >> H;
  int count = 0;
  while (true) {
    H = H / 2;
    count++;
    if (H == 1)
      break;
  }
  //	cout<<count<<endl;
  long long sum = 0;
  for (int i = 0; i <= count; i++) {
    sum += pow(2, i);
  }
  cout << sum << endl;
}

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

int main() {
  long long H;
  cin >> H;
  int count = 0;
  if (H == 1) {
    cout << 1 << endl;
    return 0;
  }
  while (true) {
    H = H / 2;
    count++;
    if (H == 1)
      break;
  }
  //	cout<<count<<endl;
  long long sum = 0;
  for (int i = 0; i <= count; i++) {
    sum += pow(2, i);
  }
  cout << sum << endl;
}
Problem p02786 (C++)

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

int main() {
  long H;
  cin >> H;
  long cnt = 0;
  long i = 0;
  while (H >= 1) {
    cnt += pow(2, i);
    i++;
  }
  cout << cnt;
}

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

int main() {
  long H;
  cin >> H;
  long cnt = 0;
  long i = 0;
  while (H >= 1) {
    cnt += pow(2, i);
    i++;
    H = H / 2;
  }
  cout << cnt;
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long dfs(long long n) {
  if (n == 1)
    return 1;
  else
    return dfs(n / 2) + dfs(n / 2) + 1;
}
int main() {
  long long n;
  cin >> n;
  cout << dfs(n);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long dfs(long long n) {
  if (n == 1)
    return 1;
  else
    return dfs(n / 2) * 2 + 1;
}
int main() {
  long long n;
  cin >> n;
  cout << dfs(n);
  return 0;
}
Problem p02786 (C++)

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

signed main() {
  int H;
  cin >> H;

  if (H == 1) {
    puts("1");
    return 0;
  }

  int b = 1;
  while ((1 << b) <= H)
    b++;
  cout << (1 << b) - 1 << endl;
}

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

signed main() {
  int H;
  cin >> H;

  if (H == 1) {
    puts("1");
    return 0;
  }
  int b = (int)log2(H) + 1;
  cout << (1LL << b) - 1 << endl;
}
Problem p02786 (C++)

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

long solve(long n) {
  if (n == 1)
    return 1;
  else
    return 2 * solve(n / 2) + 1;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input", "r", stdin);
  freopen("output", "w", stdout);
#endif

  long n;
  cin >> n;
  long ans = solve(n);
  cout << ans;

  return 0;
}

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

long solve(long n) {
  if (n == 1)
    return 1;
  else
    return 2 * solve(n / 2) + 1;
}

int main() {

  long n;
  cin >> n;
  long ans = solve(n);
  cout << ans;

  return 0;
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
本宝的程序外人别想看！！

name: [夏宝宝]
run time：[] ms
compilation time: [] ms
output memory: [] MiB
where: []
state: []
*/
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int s1, s2 = 1;

  cin >> s1;

  long long int sum;

  while (s2 > 0) {
    sum += s2;
    s2 *= 2;
    s1 = floor(s1 / 2);
  }

  cout << sum << endl;

  return 0;
}

Fixed submission:
/*
本宝的程序外人别想看！！

name: [夏宝宝]
run time：[] ms
compilation time: [] ms
output memory: [] MiB
where: []
state: []
*/
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int s1, s2 = 1;

  cin >> s1;

  long long int sum;

  while (s1 > 0) {
    sum += s2;
    s2 *= 2;
    s1 = floor(s1 / 2);
  }

  cout << sum << endl;

  return 0;
}
Problem p02786 (C++)

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

int main() {
  ll h;
  cin >> h;
  ll r = 1;
  while (h) {
    h >> 1;
    r << 1;
  }

  cout << r - 1 << endl;
}

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

int main() {
  ll h;
  cin >> h;
  ll r = 1;
  while (h) {
    h >>= 1;
    r <<= 1;
  }

  cout << r - 1 << endl;
}
Problem p02786 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long int h, c = 1, x = 0, v = 0, i, p = 0;
  cin >> h;
  while (1) {
    h = h / 2;
    c = c * 2;
    p += c / 2;

    if (h == 1) {
      break;
    }
  }
  p = c + p;

  cout << p << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long int h, c = 1, x = 0, v = 0, i, p = 0;
  cin >> h;
  if (h == 1) {
    cout << "1" << endl;
    return 0;
  }
  while (1) {
    h = h / 2;
    c = c * 2;
    p += c / 2;

    if (h == 1) {
      break;
    }
  }
  p = c + p;

  cout << p << endl;

  return 0;
}