Problem:
 Score : 400 points    Problem Statement 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 1 2      Sample Output 1 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.       Sample Input 2 4      Sample Output 2 7       Sample Input 3 1000000000000      Sample Output 3 1099511627775

Solution (Python):
h=int(input())
i=0
ans=0
while True:
    if h>0:
        h=h//2
        ans+=2**i
        i+=1
    else:
        break
print(ans)

Solution (Python):
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop


sys.setrecursionlimit(10 ** 7)

H = int(input())

a = 0
h = H
while(h > 0):
    h = h // 2
    a += 1

ans = (1-2**a) * (-1)
print(ans)

Solution (Python):

import re
import math
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline

mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 

 

h=int(input())
ans=1
if h==1:print(1)
else:
    for a in range(1,10000):
        h=h//2
        ans+=pow(2,a)
        if h==1:
            break
    print(ans)

Solution (Python):

''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"
exit $?
'''
import sys


def _i(): return int(sys.stdin.readline().strip())


h = _i()

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

print(2**n - 1)

Solution (Python):
def rec(H):
    if H == 1:
        return 1
    else:
        return 1 + rec(H//2)*2

H = int(input())
print(rec(H))

Solution (Python):
import numpy as np

H = int(input())

num = 0
for i in range(2**100):
    num += 2**i
    H = H // 2

    if H == 0:
        break

print(num)

Solution (Python):
from sys import stdin

H = int(stdin.readline().rstrip())
cnt = 0

while H > 1:
    if H % 2 == 1:
        H = (H - 1) // 2
    else:
        H //= 2
    cnt += 1

print(2 ** (cnt + 1) - 1)

Solution (Python):
h=int(input())
a=0
while h!=0:
  h=h//2
  a=a+1
print(2**a-1)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    h = II()
    ans = 0
    while h:
        h = h >> 1
        ans += 1
    print(2 ** ans - 1)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
def main():
    h=int(input())
    c=0
    x=1
    for i in range(1,h+1):
        if h>1:
            h=h//2
            c+=x
            x*=2
        else:
            c+=x
            break
    print(c)
    
if __name__ == '__main__':
    main()

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

Solution (Python):
h = int(input())

for i in range(300):
    if 2**i <= h < 2**(i+1):
        print(2**(i+1)-1)
        exit()

Solution (Python):
H = int(input())
ans = 0

mons_num = 1

while(1):
    if H == 0:
        break
    ans += mons_num
    mons_num *= 2
    H = H // 2

print(ans)

Solution (Python):
from sys import stdin
import math
n = int(stdin.readline().rstrip())
i = 0
while True:
    if 2**i > n:
        break
    i += 1
point = 0
for j in range(i):
    point += 2**j
print(point)

Solution (Python):
h=int(input())

ans=0
i=0
while True:
    ans+=(2**i)
    h//=2
    i+=1
    if h==0:
        break
print(ans)

Solution (Python):
h = int(input())
total = 0
n = 1
for i in range(10**6):
  if h >= 1:
    total += n
    h = h // 2
    n *= 2
  if h <= 0:
    break
print(total)

Solution (Python):
import math

def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

def splitintinput():
    return map(int,input().split())

H = intinput()
print(2**(int(math.log2(H)+1))-1)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

H = int(input())

def c(hp, cnt):
    if hp//2 > 0:
        return c(hp//2, cnt+1)
    else:
        return cnt+1

print(2**c(H, 0)-1)

Solution (Python):
def attack(N):
    if N==1:
        return 1
    else:
        return 1+2*attack(N//2)
H=int(input())
print(attack(H))

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok


def main():
    H=ii()
    c = 1
    ans = 0
    while H:
        ans += c
        H >>= 1
        c <<= 1
    print(ans)

main()

Solution (Python):
import sys


def main():
    h = int(sys.stdin.readline().strip())

    def solve(point):
        if point == 1:
            return 1
        return 1 + 2 * solve(point // 2)

    print(solve(h))


if __name__ == '__main__':
    main()

Solution (Python):




def solve(inp):
    H = int(inp.readline().strip())

    n = 1
    r = 1
    while True:
        n *= 2
        if n > H:
            break
        r = r * 2 + 1

    return r


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

H = int(input())

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

print(calc(H))

Solution (Python):

h = int(input())
ans = 0
num = 1
while True:
    if h == 1:
        ans += num
        break
    else:
        h = h//2
        ans += num
        num *= 2
print(ans)

Solution (Python):
h = int(input())

two = 0
while h:
    h //= 2
    two += 1

print(2 ** two - 1)

Solution (Python):
h = int(input())
t=1
ans=0
while True:
    h=h//2
    ans+=t
    t*=2
    if h==0:
        break
print(ans)

Solution (Python):
h = int(input())
n = 0

while h:
  h >>= 1
  n += 1
print(2**n - 1)

Solution (Python):
H = int(input())

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

print(ans)

Solution (Python):
H=int(input())
h=1
while (H>h-1):
    h*=2
print(h-1)

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

Solution (Python):
h = int(input())

tmp = 1
ans = 1

while h != 1:
    h //= 2
    tmp *= 2
    ans += tmp

print(ans)

Solution (Python):
import math
def main():
    H = int(input())
    t = int(math.log2(H))
    r = 2**(t + 1) - 1
    print(r)
main()

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

Solution (Python):
def main():
  H=int(input())
  monster=1
  count=0
  while(H!=0):
    H//=2
    count+=monster
    monster=2*monster
  print(count)
main()

Solution (Python):
H = int(input())

c = 0
while H > 1:
  H //= 2
  c += 1

print(2**(c+1)-1)

Solution (Python):
H=int(input())

k=1
N=0
while H>0:
  H=H//2
  N+=k
  k*=2
print(N)

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

def getlist():
	return list(map(int, input().split()))


def main():
	H = int(input())
	ans = 1
	for i in range(50):
		if 2 ** i > H:
			ans = 2 ** i - 1
			break

	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
h = int(input())
T = [[h,1]]
s = 0

l = 10**6 + 3
A = [0] * l
A[1] = 1
for i in range(2, l):
    A[i] = 1 + A[i//2] * 2
a = 0
while s < len(T):
    if T[s][0] >= l:
        T.append([T[s][0]//2, T[s][1]*2])
        a += T[s][1]
        T[s] = [0,0]

    s += 1




for i in range(len(T)):
    a += A[T[i][0]] * T[i][1]
print(a)

Solution (Python):
import math

h = int(input())

n = math.floor(math.log2(h))
ans = 2**(n+1)-1

print(ans)

Solution (Python):
H = int(input())
h = H
result = 0
i = 1
while 0<h:
    h = H // (2**i)
    result += 2**(i-1)
    i += 1

print(result)

Solution (Python):
h = int(input())

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

Solution (Python):
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

h = ni()
c = 0
s = 1
while h > 1:
    h //= 2
    c += 1
    s += 2 ** c
print(s)

Solution (Python):
def hit(h):
    ans = 0
    if h == 1:
        ans += 1
    else:
        ans += 2*hit(h//2) + 1
    return ans
  
if __name__ == '__main__':
    print(hit(int(input())))

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

Solution (Python):
h = int(input())

i = 0
now = 0
while now < h:
    now = 2 ** i
    if now >= h:
        break
    i += 1

if 2 ** i == h:
    pass
else:
    i = i -1

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

print(ans)

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

Solution (Python):
H = int(input())
i = 0
while H!=0:
  H//=2
  i+=1
  
print(pow(2,i)-1)

Solution (Python):
H = int(input())

result = 0
i = 1
while 'true':
    if H == 1:
        break
    else:
        H //= 2
        result += i
        i *= 2
        
        
print(result + i)

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

Solution (Python):
H = int(input())

cnt = 0

for i in range(1, 40):
    if 2**i <= H: cnt += 1


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

print(ans)

Solution (Python):
import math
import sys
h = int(input())



c = 1
while (True):
    if h <= 2 ** c - 1:
        print(2 ** c - 1)
        break

    c += 1

Solution (Python):
def f(n):
    if n==1:
        return 1
    return 1+2*f(n//2)
print(f(int(input())))

Solution (Python):
H = int(input())

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

Solution (Python):
from math import ceil,log2

def main():
    H = int(input())
    lg = log2(H)
    ans = 0
    cnt = 0
    while H > 0:
        ans += 2**cnt
        cnt += 1
        H = H // 2
    print(ans)
    return
if __name__ == "__main__":
    main()

Solution (Python):
H = int(input())
bit_digit = 1

while H > 1:
    H >>= 1
    bit_digit += 1

ans = (1 << bit_digit) - 1

print(ans)

Solution (Python):
H = int(input())

n = 0
while H > 0:
    H //= 2
    n += 1

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

Solution (Python):
h=int(input())
ans=0
t=1
while t<=h:
    t*=2
print(t-1)

Solution (Python):
H = int(input())


cnt = 0
while H != 0:
    H = H // 2
    cnt += 1


ans = 0
for i in range(cnt):
    x = 2 ** i
    ans += x

print(ans)

Solution (Python):
h = int(input())

count = 0

n = 1
while n <= h:
    count += n
    n *= 2
print(count)

Solution (Python):
h = int(input())

cnt = 1
ans = 0
while True:
  if h == 1:
    ans += cnt
    break
  else:
    h //= 2
    ans += cnt
    cnt *= 2

print(ans)

Solution (Python):




import heapq

get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]


H = get()

heap = [[H, 1]]
res = 0
while heap:
    h, n = heapq.heappop(heap)
    res += n
    if h == 1: continue
    heapq.heappush(heap, [h / 2, n * 2])

print res

Solution (Python):
import math
def A():
    temp = [int(i) for i in input().split()]
    print(int(math.ceil(temp[0]/temp[1])))

def B():
    temp = [int(i) for i in input().split()]
    H = temp[0]
    N = temp[1]
    A = [int(i) for i in input().split()]
    if H <= sum(A):
        print('Yes')
    else:
        print('No')

def C():
    temp = [int(i) for i in input().split()]
    N = temp[0]
    K = temp[1]
    H = [int(i) for i in input().split()]
    if N <= K:
        print(0)
        return
    H.sort(reverse=True)
    print(sum(H[K:]))

def D():
    H = int(input())
    factor = 0
    ans = 0
    while True:
        ans += 2**factor
        if H == 1:
            break
        H = math.floor(H/2)
        factor += 1
    print(ans)
D()

Solution (Python):
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))

Solution (Python):
h = int(input())

ans = 0
count = 0

while(True):
    if(h==1):
        ans += 2**(count)
        break

    h = h//2
    ans += 2**(count)
    count += 1

print(ans)

Solution (Python):
H=int(input())
count = 1
kari=1
while True:
    if H//2>=1:
        count *= 2
        kari+=count
        H=H//2
    else:
        print(kari)
        exit()

Solution (Python):
h = int(input())

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

out = (2 ** count) -1
print(out)

Solution (Python):
h=int(input())



now=h
c=0
ans=0
while now>0:
    now=now//2
    ans+=2**c
    c+=1

print(ans)

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

Solution (Python):
import sys
from collections import deque, defaultdict
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10000000)

def Attack(L):
    if L == 1: return 1
    else:
        return 1 + 2 * Attack(L//2)

def solve():
    H = int(input())
    print(Attack(H))

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
from math import log
n = int(input())

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

Solution (Python):
H = int(input())
ans = 0
i = 1
while True:
    H = H // 2
    
    ans += i
    i *= 2
    if H == 0:
        break
print(ans)

Solution (Python):
H = int(input())

d = 1
while H >> d:
    d += 1

ans = (1 << d) - 1
print(ans)

Solution (Python):
h=int(input())

cnt=0
for i in range(10**5):
    cnt+=1
    h //=2
    if h == 0:
        print(2**cnt-1)
        exit()

Solution (Python):
h = int(input())

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



print(2 ** count - 1)

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import math

H=one_int()

beki = int(math.log2(H))+1

print(2**beki -1 )

Solution (Python):

import sys


def solve(H: int):
    ans = 1
    x = 1
    while H != 1:
        H = H // 2
        x *= 2
        ans += x
    print(ans)
        


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    solve(H)

if __name__ == '__main__':
    main()

Solution (Python):
H = int(input())

life = H
enemy = 1
ans = 1

while True:
    life //= 2
    if life <= 0:
        break
    enemy *= 2
    ans += enemy

print(ans)

Solution (Python):
H = int(input())

x = 1
while H > 1:
    x = 1 + 2*x
    H //= 2

print(x)

Solution (Python):
def main():
    H = int(input())

    power = 0
    ans = 0
    while 0 < H:
        H = H // 2
        ans += 2**power
        power += 1

    print(ans)


main()

Solution (Python):
import math
n=int(input())
t=int(math.log(n,2))
print(int(math.pow(2,t+1))-1)

Solution (Python):
h = int(input())
res = 0
t = 1
while h >= 1:
    h //= 2
    res += t
    t *= 2
print(res)

Solution (Python):
H = int(input())


count = 0
while H > 0:
    H //= 2
    count +=1
bit = '1'*count
print(int(bit,2))

Solution (Python):
import math
H = int(input())
ans = 0
now_hp = H
now_numofmonster = 1
while (now_hp != 0):
    ans += now_numofmonster
    now_hp = math.floor(now_hp / 2)
    now_numofmonster *= 2
print(ans)

Solution (Python):
h=int(input())
cnt=0
while h>0:
    cnt+=1
    h=h//2
ans=0
for i in range(cnt):
    ans+=2**i
print(ans)

Solution (Python):
h = int(input())
ans = 0
n = 1
while(True):
  ans += n
  if h == 1:
    break
  h //= 2
  n *= 2
print(ans)

Solution (Python):
H=int(input())

k=0
count=0
while True:
    H=H//2
    count+=(2**k)

    if H==0:
        break
    k+=1


print(count)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    h = II()
    r = h
    ans = [1]
    while r > 0:
        r = r // 2
        if r > 0:
            ans.append(ans[-1] * 2)
    print(sum(ans))



if __name__ == '__main__':
    main()

Solution (Python):
h = int(input())
ht = list(format(h, 'b'))
n = len(ht)
result = 0
for i in range(n):
    result += 2**i
print(result)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  c=1
  h=I()
  ans=0

  while True:
    ans+=c
    if h==1:
      break

    h//=2
    c*=2

    

  return ans


print(main())

Solution (Python):
def solve(h):
    if h == 1:
        return 1
    else:
        return 2 * solve(h // 2) + 1


def main():
    h = int(input())
    res = solve(h)
    print(res)


def test():
    assert solve(2) == 3
    assert solve(4) == 7
    assert solve(1000000000000) == 1099511627775


if __name__ == "__main__":
    test()
    main()

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush

sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) 
def inpm(): return map(int,input().split()) 
def inpl(): return list(map(int, input().split())) 
def inpls(): return list(input().split())  
def inplm(n): return list(int(input()) for _ in range(n)) 
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return sorted([list(map(int, input().split())) for _ in range(n)]) 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def main():
    h = inp()
    x = []
    while h>0:
        x.append(h%2)
        h //= 2
    s = sum(x)
    n = len(x)
    for i in range(n):
        if x[i] > 0:
            x[i] = s
            s -= 1
        else:
            x[i] = s
    ans = 0
    for i in range(n):
        ans += pow(2,i)
    print(ans)
    
if __name__ == "__main__":
    main()

Solution (Python):
h=int(input())
count=0
while h!=0:
	h//=2
	count+=1
print(2**count-1)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def main():
    H = I()

    count = 0
    while(H>0):
        H = H // 2
        count += 1

    print(pow(2,count)-1)



if __name__ == "__main__":
    main()

Solution (Python):
def f(x):
  if(x==1):
    return 1
  else:
    return 2*f(x//2) + 1
h = int(input())
print(f(h))

Solution (Python):
import sys
import fractions
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

H = I()
print(tami(H))

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

Solution (Python):

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

Solution (Python):
import math
h=int(input())
c=math.log2(h)
c=math.floor(c)
ans=1
now=1
for i in range(c):
    now*=2
    ans+=now
print(ans)

Solution (Python):
import math
H = int(input())
f = [1]
for i in range(40):
    f.append(f[-1]+2**(i+1))
tmp = int(math.log2(H))
print(f[tmp])

Solution (Python):
def main():
    h = int(input())
    cnt = 0
    x = 1
    while h:
        cnt += x
        h //= 2
        x *= 2
    print(cnt)


main()

Solution (Python):
import math

def log2(x):
    return math.log(x) / math.log(2)

H = int(input())

log2H = int(log2(H))
ans = 0

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

print(ans)

Solution (Python):
H = int(input())

ans = 0
tmp = 1

while H:
    ans += tmp
    tmp *= 2
    H //= 2

print(ans)

Solution (Python):
from collections import defaultdict

H = int(input())
cnt = defaultdict(int)

def dfs(n):
  if cnt[n]:
    return cnt[n]
  else:
    if n == 1:
      return 1
    else:
      return 2 * dfs(n // 2) + 1

print(dfs(H))

Solution (Python):
h = int(input())

count = 0
i = 1
while h > 0:
    h //= 2
    count += i
    i *= 2
print(count)

Solution (Python):
import math

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

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

Solution (Python):
h = int(input())
k = 0
while True:
    if 2**k <= h < 2**(k+1):
        break
    else:
        k += 1
ans = 1
for i in range(k):
    ans = 2 * ans + 1
print(ans)

Solution (Python):
n = int(input())
k = 1

while True:
  max_ = 2 ** k - 1 
  if n <= max_:
    print(max_)
    break
  else:
    k += 1

Solution (Python):
import math

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

Solution (Python):
H = int(input())

count = 1
ans = 0
while H > 0:
    H //= 2
    ans += count
    count *= 2

print(ans)

Solution (Python):
H = int(input())
i = 1
S = 0
while H != 0:
  S += i
  H //= 2
  i *= 2
print(S)

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

Solution (Python):
H = int(input())

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

Solution (Python):
import sys
H = int(input())


sys.setrecursionlimit(1000000)


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


print(f(H))

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

def f(X):
    if X not in memo:
        if X == 1:
            memo[X] = 1
        else:
            memo[X] = 2 * f(X//2)
    return memo[X]

H = int(input())

memo = {}
ans = f(H)

print(ans*2-1)

Solution (Python):
import math
H=int(input())
a=int(math.log(H,2))
print(2**(a+1)-1)

Solution (Python):
H = int(input())
count = 1
times = 0
while H > 1:
    H >>= 1
    times += count
    count <<= 1
times += count
print(times)

Solution (Python):
h = int(input())

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

print(attack(h))

Solution (Python):
h=int(input())
i=0
ans=0
while h>0:
    ans+=(1<<i)
    h//=2
    i+=1
print(ans)

Solution (Python):
def main():
    H = int(input())
    if H == 1:
        print(1)
        exit()
    cnt = 1
    ans = 0
    while H > 1:
        H //= 2
        ans += cnt
        cnt *= 2

    print(ans + cnt)




if __name__ == "__main__":
    main()

Solution (Python):
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10**5+10
MOD = 10**9+7
spf = [i for i in range(MAXN)]
spf[0]=spf[1] = -1
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]

def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))

def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))

def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD

    return (num*(pow(den,MOD-2,MOD)))%MOD

def flush():
    return sys.stdout.flush()

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''

d = {}
def fun(n):

    if n==1:
        return 1
    if d.get(n):
        return d[n]
    ans = 0
    ans+=1+2*fun(n//2)

    d[n] = ans
    return d[n]

n = int(input())
print(fun(n))

Solution (Python):
H = int(input())


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


print(attack(H))

Solution (Python):
h=int(input())
atk=0
n=1
while h>1:
    h//=2
    atk+=n
    n*=2
print(n+atk)

Solution (Python):
import os,sys
from io import BytesIO, IOBase

def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())

def gcd(x,y):
    while(y):
        x,y=y,x%y
    return x
    

mod=(10**9)+7

import math 
        
for i in range(1):
    h=ii()
    a=math.log(h,2)
    a=int(a)
    a+=1
    ans=pow(2,a)
    ans-=1 
    print(ans)

Solution (Python):
h = int(input())
cnt = 0
i = 1
while h > 1:
    cnt += i
    h = h//2
    i *= 2
cnt += i
print(cnt)

Solution (Python):
H = int(input())

count = 0
monster = 1
while H != 1:
    H //= 2
    count += monster
    monster *= 2
    
count += monster
print(count)

Solution (Python):
def fun(h):
    if h==1:
        return 1
    elif h==0:
        return 0
    else:
        return 2*fun(int(h/2))+1
h = int(input())
print(fun(h))

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

Solution (Python):
H = int(input())

ans = 0
cnt = 1
while H != 0:
    ans += cnt
    H //= 2
    cnt *= 2

print(ans)

Solution (Python):
a = int(input())
count = -1
ans = 0
while a != 0:
  a //= 2
  count += 1
  ans += 2**count
print(ans)

Solution (Python):
h = int(input())














mm = 1
ans = 0
for i in range(100):
    ans += mm
    mm *= 2

    if ans >= h:
        print(ans)
        break

Solution (Python):
H = int(input())
base = 1
ans = 0
while H > 0:
    H //= 2
    ans += base
    base += base
print(ans)

Solution (Python):
h=int(input())
ans=0
i=0
while h>0:
    ans+=2**i
    i+=1
    h=h//2

print(ans)

Solution (Python):
H = int(input())

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

Solution (Python):
from math import log2

H = int(input())
N = int(log2(H))
r = 1
for i in range(N):
    r += (2**(1+i))
print(r)

Solution (Python):


def resolve():
    H=int(input())
    nom=1
    count=0
    while H!=0:
        H//=2
        count+=nom
        nom *=2
    print(count)



if __name__ == "__main__":
    resolve()

Solution (Python):
N = int(input())
cnt = 0
ans = 0
while N>0:
  ans +=2**cnt
  N=N//2
  cnt+=1
print(ans)

Solution (Python):
H = int(input())

ans = 0
attack = 1
while(True):
    ans += attack
    H = H //2
    attack = attack *2

    if(H==0):
        break


print(ans)

Solution (Python):
h = int(input())

ans = 0

x = 1

while h > 0:
    h = h // 2
    ans += x
    x *= 2

print(ans)

Solution (Python):
import math
h = int(input())
monst = 1
x = 0
while h > 1:
    x += monst
    monst *= 2
    h = math.floor(h/2)
x += monst
print(x)

Solution (Python):
H = int(input())

cnt = 0
while H > 1:
	cnt += 1
	H //= 2
ans = 0
for i in range(cnt):
	ans += (2**i)

ans += 2**cnt

print(ans)

Solution (Python):
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans




a = int(input())

times=0

for i in range(999):
    if(a==0):
        break
    a = a//2
    times+=1
    


print(2**times-1)

Solution (Python):
h=int(input())
i=0
cnt=0
while h:
    cnt+=2**i
    h//=2
    i+=1
print(cnt)