Problem p02786 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rg register
#define us unsigned
#define ll long long
#define ui <int>
#define pi <int, int>
#define tmpl template <typename typ>
#define oprt operator
#define sp putchar(32)
#define el putchar(10)
#define flin(x) freopen(x, "r", stdin)
#define flout(x) freopen(x, "w", stdout)
#define flio(x) flin(x ".in"), flout(x ".out")
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define itrt iterator
using namespace std;
tmpl inline bool up(typ &x, const typ &y) { return x < y ? x = y, 1 : 0; }
tmpl inline bool dn(typ &x, const typ &y) { return y < x ? x = y, 1 : 0; }
tmpl inline bool inr(const typ &x, const typ &l, const typ &r) {
  return !(x < l) && !(r < x);
}
namespace orh {
inline void useios() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
inline char rc() {
  rg char ch;
  while (!isgraph(ch = getchar()))
    ;
  return ch;
}
tmpl typ ri() {
  rg typ x = 0;
  rg bool neg = false;
  rg char ch;
  while (!inr(ch = getchar(), '0', '9'))
    neg |= ch == '-';
  do
    x = (x << 1) + (x << 3) + (ch ^ 48);
  while (inr(ch = getchar(), '0', '9'));
  return neg ? -x : x;
}
tmpl typ ru() {
  rg typ x = 0;
  rg char ch;
  while (!inr(ch = getchar(), '0', '9'))
    ;
  do
    x = (x << 1) + (x << 3) + (ch ^ 48);
  while (inr(ch = getchar(), '0', '9'));
  return x;
}
tmpl void wi(rg typ x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static int sta[42];
  rg int top = 0;
  rg typ t;
  do
    t = x / 10, sta[top++] = x - (t << 1) - (t << 3), x = t;
  while (x);
  while (top)
    putchar(sta[--top] ^ 48);
}
tmpl void wu(rg typ x) {
  static int sta[42];
  rg int top = 0;
  rg typ t;
  do
    t = x / 10, sta[top++] = x - (t << 1) - (t << 3), x = t;
  while (x);
  while (top)
    putchar(sta[--top] ^ 48);
}
} // namespace orh

ll n;

ll dfs(int x) {
  if (x == 1)
    return 1;
  ll t = dfs(x / 2ll);
  return t + t + 1;
}

signed main() {
  orh::useios();

  cin >> n;

  cout << dfs(n) << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rg register
#define us unsigned
#define ll long long
#define ui <int>
#define pi <int, int>
#define tmpl template <typename typ>
#define oprt operator
#define sp putchar(32)
#define el putchar(10)
#define flin(x) freopen(x, "r", stdin)
#define flout(x) freopen(x, "w", stdout)
#define flio(x) flin(x ".in"), flout(x ".out")
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define itrt iterator
using namespace std;
tmpl inline bool up(typ &x, const typ &y) { return x < y ? x = y, 1 : 0; }
tmpl inline bool dn(typ &x, const typ &y) { return y < x ? x = y, 1 : 0; }
tmpl inline bool inr(const typ &x, const typ &l, const typ &r) {
  return !(x < l) && !(r < x);
}
namespace orh {
inline void useios() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
inline char rc() {
  rg char ch;
  while (!isgraph(ch = getchar()))
    ;
  return ch;
}
tmpl typ ri() {
  rg typ x = 0;
  rg bool neg = false;
  rg char ch;
  while (!inr(ch = getchar(), '0', '9'))
    neg |= ch == '-';
  do
    x = (x << 1) + (x << 3) + (ch ^ 48);
  while (inr(ch = getchar(), '0', '9'));
  return neg ? -x : x;
}
tmpl typ ru() {
  rg typ x = 0;
  rg char ch;
  while (!inr(ch = getchar(), '0', '9'))
    ;
  do
    x = (x << 1) + (x << 3) + (ch ^ 48);
  while (inr(ch = getchar(), '0', '9'));
  return x;
}
tmpl void wi(rg typ x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static int sta[42];
  rg int top = 0;
  rg typ t;
  do
    t = x / 10, sta[top++] = x - (t << 1) - (t << 3), x = t;
  while (x);
  while (top)
    putchar(sta[--top] ^ 48);
}
tmpl void wu(rg typ x) {
  static int sta[42];
  rg int top = 0;
  rg typ t;
  do
    t = x / 10, sta[top++] = x - (t << 1) - (t << 3), x = t;
  while (x);
  while (top)
    putchar(sta[--top] ^ 48);
}
} // namespace orh

ll n;

ll dfs(ll x) {
  if (x == 1)
    return 1;
  ll t = dfs(x / 2ll);
  return t + t + 1;
}

signed main() {
  orh::useios();

  cin >> n;

  cout << dfs(n) << endl;

  return 0;
}