Caracal is fighting with a monster.
The health of the monster is H.
Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:
 - If the monster's health is 1, it drops to 0.
 - If the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \lfloor X/2 \rfloor.
(\lfloor r \rfloor denotes the greatest integer not exceeding r.)
Caracal wins when the healths of all existing monsters become 0 or below.
Find the minimum number of attacks Caracal needs to make before winning.

-----Constraints-----
 - 1 \leq H \leq 10^{12}
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
H

-----Output-----
Find the minimum number of attacks Caracal needs to make before winning.

-----Sample Input-----
2

-----Sample Output-----
3

When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of 1.
Then, Caracal can attack each of these new monsters once and win with a total of three attacks.

Difficulty: interview

Starter code:

Solutions:
h = int(input())
ans = 0
n = 0
while h != 0:
  ans += 2**n
  n += 1
  h = h//2
print(ans)

H = int(input())

cnt = 0
res = 0

while H > 1:
    H = H //2
    cnt += 1
    res += 2**cnt

print(res+1)

H = int(input())
now = 1
for i in range(1,100):
  if now <= H <= now*2-1:
    print((2**i-1))
    break
  else:
    now *= 2


def N():
    return int(input())
def L():
    return list(map(int,input().split()))
def NL(n):
    return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7

#import numpy as np
import sys
import math
import collections

n = N()
l = int(math.log2(n))
su = 0
z = 1
for i in range(l+1):
    su += z
    z *= 2
print(su)

H = int(input())

cnt = 0

while H:
  H //= 2
  cnt = cnt*2 + 1

print(cnt)


H = int(input())
 
# 体力がHのモンスター1体に勝つために必要な攻撃回数をf(H)とする
# すると、f(H)は以下の漸化式に従って求まる
# f(H)=2*f(floor(H/2)+1) (H>1)
# f(H)=1 (H=1)

# 漸化式の実装はAtCoderで珍しい。パターンとして覚えよ！
def attack_num(x):
  if x == 1: return 1
  else: return 2*attack_num(x // 2) + 1
  
print(attack_num(H))

import math
H = int(input())
l = math.log(H,2)
ll = math.floor(l)+1
ans = 2 ** ll -1
print(ans)

import math

h = int(input())
atk = 0
enemy = 1

while True:
    if h > 1:
        h = math.floor(int(h/2))
        atk += enemy
        enemy *= 2
    elif h == 1:
        atk += enemy
        break

print(atk)


import math
h=int(input())
print((2**(math.floor(math.log2(h))+1)-1))


h = int(input())
sumn = 0
i,k = 0,1
while k <= h:
    sumn+=k
    i+=1
    k = 2**i
    
print(sumn)

def myfunc(N):
	if(N  <= 1):
		return 1
	return 2 * myfunc(int(N/2)) + 1

def __starting_point():
	N = int(input())
	print(myfunc(N))
__starting_point()

H = int(input())
count = 0
while H != 1:
    H //= 2
    count += 1
ans = 0
for i in range(count +1):
    ans += 2 ** i
print(ans)


import math

h = int(input())
print(2 ** (math.floor(math.log2(h)) + 1) - 1)

h=int(input())
def fh(x):
    if x==1:
        return 1
    else:
        return 2*fh(x//2)+1
ans=fh(h)
print(ans)

# 26
H = int(input())

def getAns(x):
    if x <= 1: return 1
    return 2 * getAns(x // 2) + 1

ans = getAns(H)

print(ans)

H = int(input())
c = 1
ans = 1
while H>1:
  H //= 2
  c *= 2
  ans += c
print(ans)

def divi(n):
  if n > 1:
    return 2*divi(n//2) + 1
  else:
    return 1
h = int(input())
print(divi(h))

h = int(input())

def wa(n):
    w = 0
    for i in range(0,n+1):
        w += 2**i
    return w

n = 1
cnt = -1
while n<=h:
    n = n*2
    cnt += 1
print(wa(cnt))

H = int(input())
 
# 体力がHのモンスター1体に勝つために必要な攻撃回数をf(H)とする
# すると、f(H)は以下の漸化式に従って求まる
# f(H)=2*f(floor(H/2)+1) (H>1)
# f(H)=1 (H=1)

def attack_num(x):
  if x == 1: return 1
  else: return 2*attack_num(x // 2) + 1
  
print(attack_num(H))

h = int(input())

for i in range(10**12):
  if 2**i <= h < 2**(i+1):
    ans = 2**(i+1)-1
    print(ans)
    return

H = int(input())
count = 1
ans = 0

while H>0:
    H = int(H//2)
    ans += count
    count *= 2
    
print(ans)

h = int(input())
c=0
d=0
while h>1:
    h=h//2
    c+=1
    d+=2**c
print(d+1)

def mons(hp, attack=1):
    if hp == 1:
        return attack*2-1
    else:
        return mons(hp//2, attack*2)


print((mons(int(input()))))


#!/usr/bin/env python3
def main():
    H = int(input())

    res = 1
    ans = 1
    while H > 1:
        res *= 2
        ans += res
        H //= 2
    print(ans)


def __starting_point():
    main()

__starting_point()

import bisect
import numpy


H = int(input())

ans = 1
HP = 2
tmp = 1
while True:
    if H < HP:
        break
    else:
        tmp *= 2
        ans += tmp
        HP *= 2


print(ans)



import math

h = int(input())
count = 0
e = 0
while h>0:
    count += 1*2**e
    e += 1
    if h == 1:
        h =0
    else:
        h = int(math.floor(h/2))
print(count)

n = int(input())
cnt = 0
while n != 1:
    n = n // 2
    cnt += 1
ans = 1
for i in range(1, cnt+1):
    ans = ans + (2**i)
print(ans)

H = int(input())

i =0
temp = 0 
while True:
  if 2**(i)<=H and H<2**(i+1):
    temp = 2**(i)
    break
  i+=1
print (temp*2-1)

import math

H = int(input())
ans = 0
num = 0

while True:
    ans += 2**num   
    if H == 1:
        print(ans)
        break
    else:
        H = math.floor(H/2)
        num += 1

h = int(input())
ans = 0
n = 1
while h!=0:
    ans += n 
    n *= 2
    h = h//2
print(ans)

H=int(input())
cnt=0
while H>1:
    H=H//2
    cnt+=1
ans=2**(cnt+1)-1
print(ans)

H = int(input())
num = 1
sum = 0
while H != 0:
    H = H//2
    sum += num
    num *= 2
print(sum)

n=int(input())
cnt=0
i=0
ans = 0
while n!=1:
  n//=2
  i+=1
  #print(n)
  #print(i)

ans = 2**(i+1)-1
  


print(ans)
  
  


H = int(input())
attackcnt = 0
monstercnt = 1
def monster(h, m, a):
    if h == 1:
        return 0,0,a+m
    else:
        return monster(int((h/2)),2*m,a+m)
a, b, c = monster(H,monstercnt,attackcnt)
print(c)

import sys

H = int(input())
i = 0
n = 0
while True:
    if 2**i > H:
        break
    n += 2**i
    i += 1

print(n)


h = int(input())

cnt = 0
while h != 1:
    h //= 2
    cnt += 1
t = 1
ans = 0
for i in range(cnt+1):
    ans += t
    t *= 2
print(ans)

N=int(input())
import math

print(2*2**int(math.log2(N))-1)

H = int(input())

count = 0
pow = 1

for _ in range(H):
    if H < pow:
        break
    count += 1
    pow *= 2

print((2**count-1))


h = int(input())
count = 0
for i in range(40):
    count += 2**i
    if h >= 2 ** i and h < 2 ** (i+1):
        break
print(count)

H = int(input())

i = 0
while True:
  if H < 2 ** i:
    n = i
    break
  i += 1

print((2**n -1))


n = int(input())
s = 1
t = 0
while s <= n:
  s = s*2
  t += 1
print((2**t-1))  



h = int(input())

cnt = 0
num = 1
while h > 0:
    cnt += num
    h = h // 2
    num *= 2
print(cnt)

H=int(input())

N=0
while True:
    N+=1
    if 2**N>H:
        break

a=[1]*N
for i in range(N):
    if i==0:
        a[i]=1
    else:
        a[i]=2*a[i-1]+1

print(a[-1])

H = int(input())
ii = 1
while H != 1:
    ii += 1
    H = H//2
print(2**ii-1)

import math
h = int(input())
x = math.floor(math.log2(h)) + 1
y = (2 ** x) - 1
print(y)

h = int(input())
ans = 0
cnt = 1
while True:
  h = (h / 2) // 1
  ans += cnt
  if h == 0:
    print(ans)
    return
  cnt *= 2

import sys
import copy
import math
import itertools

H = int(input())
cnt = 0
for i in range(int(math.log2(H))+1):
    cnt+=2**i
print(cnt)

from math import *
H = int(input())
print(2**(int(log2(H))+1)-1)

from sys import setrecursionlimit

setrecursionlimit(1000000)

H = int(input())


def f(n):
    if n == 1:
        return 1
    else:
        return 1 + f(n // 2) * 2


print(f(H))

# -*- coding:utf-8 -*-
H = int(input())

n = 0
ans = 0
while True:
    if 2**n > H:
        break
    else:
        ans += 2**n
        n+=1

print(ans)

import math

h = int(input())
n = math.floor(math.log2(h)) + 1

print(2 ** n - 1)

print(2**int(input()).bit_length()-1)

#!/usr/bin/env python3
def main():
    def solve(n):
        if n == 1:
            return 1
        return solve(n // 2) * 2 + 1

    H = int(input())

    print((solve(H)))


def __starting_point():
    main()

__starting_point()

H = int(input())


def attack(n):
    if 1 == n:
        return 1
    return 2 * attack(int(n/2)) + 1


print((attack(H)))


H = int(input())
A = 0
ans = 0
for i in range(H):
    if 2**i <= H < 2**(i+1):
        A = 2**i
        break
    else:
        continue

for j in range(i+1):
    ans += 2**j

print(ans)


h = int(input())
count = 0
ans = 0

while h > 0:
    h //= 2
    count += 1

for i in range(count):
    ans = ans*2 + 1

print(ans)

H = int(input())
cnt = 0
while(H>0) : # ~ 40
    H = H // 2
    cnt += 1
print(2**cnt - 1)

H = int(input())

def battle(h):
  if h == 1:
    return 1
  else:
    return 2*battle(h//2)+1
print((battle(H)))



from math import log
h = int(input())
k = int(log(h,2))+1
print((2**k-1))


H = int(input())
i = 1
while H>1:
  H = H//2
  i += 1
print(2**i-1)

H = int(input())

cnt = 0
num = 1
while H >= 1:
    H = H//2
    cnt += num
    num = num*2

print(cnt)

import math
h = int(input())
hp = h
c = 0
ans = 0

while hp > 1:
    hp = math.floor(hp/2)
    c += 1
for i in range(0,c+1):
    ans += 2 ** i
print(ans)

H=int(input())
cnt=0
while H>1:
	H=H//2
	cnt+=1
print(2**(cnt+1)-1)

hp = int(input())
n = 0

while hp:
    hp //= 2
    n += 1

print(2**n-1)

h = int(input())
res = 1
c = 1
while h > 1:
  c *= 2
  res +=  c
  h //= 2
print(res)

h = int(input())
for i in range(100):
    if 2**i > h:
        print(2**i - 1)
        return

from sys import stdin
import math

h = int(stdin.readline())
split_times = math.ceil(math.log2(h+1))
sum_times = sum([2**i for i in range(split_times)])
print(sum_times)

h = int(input())

def cal(x):
  if x == 1: return 1
  return cal(x//2)*2+1

print(cal(h))

def mons(hp):
    if hp == 1:
        return 1
    else:
        return mons(hp//2)*2 + 1

print((mons(int(input()))))


H = int(input())
for i in range(0, 40):
  if 2**i <= H < 2**(i+1):
    H = 2 ** i
    break
ans = 0
for k in range(0, i+1):
  ans += 2**k
print(ans)

H = int(input())

ans = 1
if H != 1:
    h = H
    for i in range(1, 40):
        if int(h/2) >= 2:
#            print(i, ans, h, 'a')
            ans += 2**i
            h = int(h/2)
        else:
#            print(i, ans, h, 'b')
            ans += 2**i
            break

print(ans)

h = int(input())
count = 0
while True:
  h = h//2
  if h == 0:
    break
  count += 1
print(2**count+int(2**(count)-1))

def f(h):
	if h != 1:
		return f(h // 2) * 2 + 1
	else:
		return 1

h = int(input())
print((f(h)))


H=int(input())
m=1
while (m<=H):
    m*=2
print(m-1)

import numpy as np
H=int(input())
c=0
while H!=0:
  c+=1
  H=H//2

print(2**c-1)

h = int(input())
c=0
while h>0:
    h=h//2
    c+=1
print(2**c-1)

H=int(input())
b=0
while 2**b <= H:
    b+=1
print((2**(b)-1))


#!/usr/bin/env python3


def solve(H: int):
    n = 1
    attack = 0
    while H > 1:
        attack += n
        H = H // 2
        n *= 2
    attack += n
    return attack


def main():
    H = int(input())
    answer = solve(H)
    print(answer)


def __starting_point():
    main()

__starting_point()

H = int(input())
ans = 1
while H:
    H //= 2
    ans *= 2
print(ans-1)

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    enemy_hp = int(input())
    enemy_count=1
    attack_count=1

    if enemy_hp==1:
        print(1)
        return
    else:
        while enemy_hp >1:
            enemy_hp = int(enemy_hp/2)
            enemy_count*=2
            attack_count+=enemy_count
            
    print(attack_count)

def __starting_point():
    main()
__starting_point()

h=int(input())
ans=0
for i in range(10**10):
  if h==1:
    print(2**(ans+1)-1)
    break
  else:
    h//=2
    ans+=1

# coding: utf-8

def main():
    N = 0
    H = int(input())
    ans = 0

    while (True):
        H //= 2
        if H == 0:
            break
        N += 1

    for i in range(N + 1):
        ans += pow(2, i)

    print(ans)

def __starting_point():
    main()

__starting_point()

import math
H = int(input())

n = math.floor(math.log2(H))

ans = 0
for i in range(0, n+1):
    ans += 2**i
print(ans)

H = int(input())
c = 0
ans = 0
while H > 1:
    H //= 2
    ans += 2**c
    c += 1
ans += 2**c
print(ans)


def main():
    h = int(input())
    cnt = 0
    while(h>0):
        h //= 2
        cnt += 1
    x = 0
    for i in range(cnt):
        x = x * 2 +1
    print(x)
    


def __starting_point():
    main()
__starting_point()

h = int(input())
count = 1

while(h > 1):
  count += 1
  h = int(h/2)

print(2**count - 1)

import math

h = int(input())
l = int(math.log(h, 2))
p = (2**l)*2-1
print(p)


H=int(input())
s=1 #sはモンスターの数
t=0
while H>1:
    H=H//2
    s=s*2
    t=t+1

list=[]
u=1
while u<=t:
    list.append(u)
    u=u+1

z=0
for i in list:
    z=z+2**(i-1)

print(str(z+s))

H = int(input())
 
# 体力がHのモンスター1体に勝つために必要な攻撃回数をf(H)とする
# すると、f(H)は以下の漸化式に従って求まる
# f(H)=2*f(floor(H/2)+1) (H>1)
# f(H)=1 (H=1)
 
def attack_num(x):
  if x == 1: return 1
  else: return 2*attack_num(x // 2) + 1
  
print(attack_num(H))

H = int(input())
for i in range(0, 10**20 + 1):
  if 2**i <= H < 2 ** (i + 1):
    break
print(2 ** (i + 1) - 1)

h = int(input())

cnt = 0
ans = 0

while h > 1:
    h = h//2
    cnt += 1
    ans += 2**cnt

print(ans+1)

n = int(input())
ans = 1
while ans <= n:
  ans *= 2
print(ans -1)

import sys
sys.setrecursionlimit(1000000)
def rec(n):
    if n == 1: 
        return 1
    return rec(n//2)*2+1

n = int(input())
print(rec(n))

def check(n):
  if n>1:
    return 2*(check(n//2))+1
  else:
    return 1
print(check(int(input())))

H = int(input())

if H == 1:
  print((1))
  return

import math as m
n = m.floor(m.log2(H))+1
ans = (2**n) - 1

print(ans)



H = int(input())
count = 0
while H != 1:
  count += 1
  H = H >> 1
print(2 * 2**count - 1)

h = int(input())
ans = 0
e = 1
while h > 0:
    ans += e 
    e *= 2
    h = h//2
print(ans)

# D
H = int(input())
cnt = 1
ans = 0

while True:
    if 2**cnt > H:
        cnt -= 1
        break
    elif 2**cnt == H:
        break
    else:
        cnt += 1

for c in range(cnt+1):
    ans += 2**c
print(ans)


import math
h = int(input())
l = 1

while (h != 1):
    h = math.floor(h / 2)
    l += 1
ans = 0

for i in range(l):
    ans += 2**i
print(ans)

import math
h = int(input())
a,ans = 0,0
while h > 1:
  h = math.floor(h/2)
  a += 1
for i in range(a+1):
  ans += 2**i
print(ans)