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())
MAXN = 10 ** 6

dn = [None for _ in range(MAXN + 1)]


def n_attack(i):
    if i == 1:
        return 1
    elif i > MAXN:
        return 1 + 2 * n_attack(i // 2)
    elif dn[i] is not None:
        return dn[i]
    else:
        n = 1 + 2 * n_attack(i // 2)
        dn[i] = i
        return n

answer = n_attack(h)
print(answer)

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

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

total = 0
count = 0
while H>0:
    H = H//2

    total += 2**count
    count += 1

print(total)

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

if h == 1:
    print(1)
    sys.exit()
ans = 1
while h > 0:
    ans *= 2
    h //= 2

print(ans-1)

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

h = int(input())
print(func(h))

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

H=int(input())
print(f(H))

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

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

for i in range(1, 1000):
  if 2 ** i > H:
    print(2 ** i - 1)
    break

Solution (Python):
import sys












stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    H = int(stdin.readline().rstrip())
    
    
    
    
    
    
    ans = 0
    attack = 1
    while H > 1:
        ans += attack
        attack *= 2
        H = H // 2
    print(ans + attack)

if __name__ == '__main__':
    solve()

Solution (Python):









import sys
input = sys.stdin.readline

MP = int(input())
M = 1
ans = 0

while MP > 1:
    ans += M
    M = 2*M
    MP = MP//2
ans += M

print(ans)

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

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

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

print(ans)

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

H = int(input())

print(dfs(H))

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

import math

count=0
for i in range(0,h):
  if h < 1:
    break
  h = math.floor(h/2)
  count += 2**i
print(count)

Solution (Python):
h = int(input())
i = 1
while True:
    if h < 2**i:
        print(2**i-1)
        break
    i += 1

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

ans = 0
count = 1

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

Solution (Python):
h=int(input())
atc=1
num=1
while h!=1:
    h=(h/2)//1
    num=num*2
    atc=atc+num
print(atc)

Solution (Python):
from math import log2
H = int(input())
n = H.bit_length()
print(pow(2, n) - 1)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h = int(input())
d = {}
def sub(h):
    if h in d:
        return d[h]
    if h==1:
        ans = 1
    else:
        ans = sub(h//2) * 2 + 1
    d[h] = ans
    return ans
print(sub(h))

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


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


print(f(H))

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

Solution (Python):
n=int(input())
x=(bin(n))
print(2**(len(x)-2)-1)

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

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

print(ans)

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

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

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

Solution (Python):
h = int(input())
from sys import setrecursionlimit
setrecursionlimit(10**9)
def f(n):
  if n == 1:
    return 1
  else:
    return 1 + f(n//2) * 2
print(f(h))

Solution (Python):
N = int(input())
a=0
for i in range(0,100):
    if 2**i<=N<2**(i+1):
        a=i
        break
        
ans=1
for i in range(a):
    ans=2*ans+1
print(ans)

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

Solution (Python):
H = int(input())
lst = [2**i for i in range(45)] 
for i in range(45) :
    if lst[i] <= H <= lst[i+1]-1 :
        print(lst[i+1]-1)
        exit()

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

Solution (Python):
h = int(input())
lst = [2 ** i for i in range(45)]
for i in range(45):
  if lst[i] <= h <= lst[i + 1] - 1:
    print(lst[i + 1] - 1)
    exit()

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

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

for i in range(1, 10**6):
    x = 2 ** (i-1)
    y = 2 ** i - 1
    if x <= H <= y:
        ans = y
        break

print(ans)

Solution (Python):
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

H = int(input())


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


print(f(H))

Solution (Python):
import math
def f(H):
    if H==1:
        return 1
    else:
        return(2*f(math.floor(H/2))+1)
H=int(input())
print(f(H))

Solution (Python):
import math
def f(H):
    if H==1:
        return 1
    else:
        return(2*f(math.floor(H/2))+1)
H=int(input())
print(f(H))

Solution (Python):
import sys
from math import floor
def main():
    h = int(input())
    r = 0
    n = 1
    while True:
        if h == 1:
            r += n
            print(r)
            sys.exit()
        else:
            h = floor(h/2)
            r += n
            n *= 2

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque


from collections import Counter

from itertools import accumulate,combinations,permutations

from heapq import heapify,heappop,heappush


from functools import lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    

    H = int(input())
    
    
    
    

    cur=1
    tot=0
    while H>0:
        tot+=cur
        H=int(H*0.5)
        cur*=2

    print(tot)


if __name__ == "__main__":
    main()

Solution (Python):
import math

h = int(input())

t = 1
e = 1
while h > 1:
    h = math.floor(h / 2)
    e *= 2
    t += e

print(t)

Solution (Python):
h = int(input())
cnt = 0
temp = []
temp.append(1)
while h > 1:
    h = h//2
    cnt += 1
    temp.append(2**cnt)

print(sum(temp))

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

def main(i):
  if i == 1:
    return 1
  else:
    c = main(i//2)*2+1
    return c

print(main(h))

Solution (Python):
h = int(input())
ans = 0
for i in range(40) :
    h = h//2 
    if h == 0 :
        ans += 2**i
        break
    else :
        ans += 2**i
print(ans)

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

if H == 1:
  ans=1
  
H_list=[]
while H > 1:
    if H % 2 != 0:
        H=H-1
    H_list.append(H)
        
    H = H//2
    
H_list.sort()
 
ans_list=[]
for h in H_list:
    if h == 2:
        ans = 3
    else :
        ans = 2*ans+1
    ans_list.append(ans)
    
print(ans)

Solution (Python):
H = int(input())
A = 0
for i in range(H):
  if H != 1:
    H = H//2
  else:
    print(2**i-1+2**i)
    break

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

Solution (Python):
import math
def mon(h, n, k):
  if h > 1:
    h = math.floor(h / 2)
    k += n
    n *= 2
    return mon(h, n, k)
  elif h == 1:
    k += n
    return k
h = int(input())
n = 1
k = 0
print(mon(h, n, k))

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

Solution (Python):




from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""













if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip



"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""




def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): 
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) 
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) 
def mi(): return map(int, input().split()) 
def li(): return list(map(int, input().split())) 
def lw(): return input().split() 
def lcm(a, b): return abs(a * b) // gcd(a, b) 
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) 
def dd(): return defaultdict(int) 
def ddl(): return defaultdict(list) 
def write(s): return sys.stdout.write(s)














def main():
    
    h=ii()
    l=int(math.log(h,2)+1)
    print(int((2**l -1)))












    
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')



""" main function"""

if __name__ == '__main__':
    main()

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

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

attack = 2 ** c - 1
print(attack)

Solution (Python):
h = int(input())
from math import log
d = int(log(h,2))
ans = 0
for i in range(d+1):
    ans += 2**i
print(ans)

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

n = len(bin(H))-2

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

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

ans = 0
t = 1
while h != 1:
  h //= 2
  t *= 2
  ans += t
print(ans+1)

Solution (Python):






def solve(H):
    ans = 0
    monster = 1
    while True:
        ans += monster
        if H == 1:
            break
        H = H // 2
        monster *= 2
    print(ans)


if __name__ == '__main__':
    H = int(input())
    solve(H)

Solution (Python):



H = int(input())


attack_dic = {}


def calc_count(h, attack):

    if h in attack_dic:
        return attack_dic[h]

    h = h // 2
    if h>0:
        attack += calc_count(h, attack) * 2 + 1
        attack_dic[h] = attack
        return attack
    else:
        return 1
ans = calc_count(H, 0)


print(ans)

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

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

ans = 1
while h:
  h //= 2
  ans *= 2
  
ans -= 1
print(ans)

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

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

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

print(haha(x))

Solution (Python):
import math
H = int(input())
bit =math.floor(math.log(H,2))

print(pow(2,bit)*2-1)

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

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

if H == 1:
    print(1)
    
else:
    while H >= 4:  
        H = H // 2
        n += 1
    print(4 * (2 ** n) - 1)

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

def dfs(h):
    if h==1:
        return 1
    else:
        if h%2==0:
            return dfs(h//2)*2+1
        else:
            return dfs((h-1)//2)*2+1

print(dfs(H))

Solution (Python):
from sys import setrecursionlimit
setrecursionlimit(1000000)

H = int(input())

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

Solution (Python):




import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools











H = int(input())
count = 1
tmp = 2

while H > 1:
    count += tmp
    tmp = tmp * 2
    H = H//2

print(count)

Solution (Python):
import math
h = int(input())
n = math.floor(math.log2(h))
p = [0] * (n + 1)
p[0] = 1
for i in range(1, n + 1):
    p[i] = 1 + 2 * p[i - 1]
print(p[-1])

Solution (Python):
H=int(input())
m=1
a=0

while H>1:
    a=m
    H=H//2
    _m=2*m
    m=_m

print(2*m-1)

Solution (Python):
n=int(input())
i=0
while(1):
    if n==1:
        break
    n//=2
    i+=1
i=bin(i+1)[2:]
ans=1
mkr=2
for j in i[::-1]:
    if j=="1":
        ans*=mkr
    mkr*=mkr
print(ans-1)

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

n = 1
while True:
    tmp = 2**(n) -1
    if h <= tmp :
        print(tmp)
        exit()
    n += 1

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

Solution (Python):
import math
h = int(input())
x = int(math.log2(h))
print(2**(x+1) - 1)

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

Solution (Python):
import math

h = int(input())
cont=1

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

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


print(2 * pow(2, math.floor(math.log2(h))) - 1)

Solution (Python):
H=int(input())
ans=0
a=H
b=0
while a!=1:
  a=a//2
  ans+=2**b
  b+=1
else:
  ans+=2**b
print(ans)

Solution (Python):


import sys
input=sys.stdin.readline

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

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

m = 1
a = 0
while h > 1:
    h //= 2
    a += m
    m *= 2
a += m
print(a)

Solution (Python):
import sys
import math
input = sys.stdin.readline

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

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

def cal(H):
    if H > 1:
        return 2 * cal(int(H/2)) + 1
    else:
        return 1
print(cal(H))

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

def cal(H):
    if H > 1:
        return 2 * cal(int(H/2)) + 1
    else:
        return 1
print(cal(H))

Solution (Python):
import sys
import itertools

import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
h = int(input())

exp = 0
while h > 1:
    h //= 2
    exp += 1
print(2 ** (exp + 1) - 1)

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

Solution (Python):

import sys

sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)










def run():
    H = int(input())
    ret = 0
    current = 1
    while H:
        ret += current
        H = H // 2
        current *= 2
    print(ret)

if __name__ == "__main__":
    run()

Solution (Python):
H = int(input())
memo = {}
def attack(h):
  if h in memo: return memo[h]

  if h <= 1:
    memo[h] = 1
    return memo[h]
  else:
    memo[h//2] = attack(h//2)
    return 1 + memo[h//2] + memo[h//2]

print(attack(H))

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

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

TwoExp = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776]
for i in range(41):
  if H < TwoExp[i]:
    print(TwoExp[i]-1)
    break

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

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

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

Solution (Python):
H = int(input())
for i in range(10**5):
    if 2**i <= H < 2**(i+1):
        print(2**(i+1)-1)
        break

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

print(rec(H))

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

Solution (Python):
def resolve():
    import sys
    sys.setrecursionlimit(1000000)
    H = int(input())

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

    print(battle(H))

    return


resolve()

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

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

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

Solution (Python):
def main():
    h = int(input())
    ans = 0
    i = 0
    while ans < h:
        ans += 2 ** i
        i += 1
    print(ans)
    
      
if __name__ == '__main__':
    main()

Solution (Python):


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

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


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
count=0
goukei=0
while N>1:
    N=N//2
    count+=1
    goukei+=2**count



print(goukei+1)

Solution (Python):



import math


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

Solution (Python):
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

h = i()

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()

H = ini()


def solve(h):
    if h == 1:
        return 1
    return 1 + 2 * solve(h >> 1)


print(solve(H))

Solution (Python):
import math
h=int(input())
x=h
a=0
ans=0
while(h!=0):
  h=math.floor(h/2)
  a+=1
for i in range(0,a):
  ans+=pow(2,i)
print(ans)

Solution (Python):

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

Solution (Python):
n = int(input())
c = 0
i = 0

while n>0:
    n = int(n/2)
    c += 2**i
    i += 1
    
print(c)

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

Solution (Python):
def solve():
    H = int(input())
    ans = 1
    if H >1:
        x = 1
        while x<= H:
            x*= 2
        ans = x-1
    print(ans)


if __name__ == '__main__':
    solve()

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

Solution (Python):
import math

H = int(input())

n = 1
while H > 1:
    H = math.floor(H / 2)
    n = n + 1

attack = 0
for i in range(n):
    attack = attack + 2 ** i

print(attack)

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

Solution (Python):

import sys
import math

def solve(H: int):
    D = int(math.log2(H)) + 1
    cnt = 0
    for d in range(D):
        cnt += 2 ** d
    print(cnt)
    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):
def a(h):
  if h<2:
    return 1
  return 1+2*a(h//2)
print(a(int(input())))

Solution (Python):
def attack(h, n):
  n += 1
  if h <= 1: 
    return n
  return attack(h//2, n*2)

n = 0
H = int(input())
N = attack(H, n)

print(N)

Solution (Python):
import sys
input = sys.stdin.readline

h = int(input())

def hit(h, s):
    if h == 1:
        return s+1
    else:
        return 2 *hit(h//2, s) + 1

print(hit(h, 0))

Solution (Python):






H = int(input())





import math





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

Solution (Python):
print(~-(1<<len(bin(int(input()))[2:])))

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

Solution (Python):
def attack(n):
    ans = 0
    if n == 1:
        ans += 1
    else:
        ans += 2*attack(n//2)+1

    return ans

h = int(input())
print(attack(h))

Solution (Python):
def battle(x):
    if x == 1:
        return 1
    else:
        return 1+2*battle(x//2)

h = int(input())

print(battle(h))

Solution (Python):
h = int(input())
count = 1
while True:
    if count > h:
        print(count - 1)
        break
    else:
        count *= 2

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

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

Solution (Python):
h = int(input())
ans = 0
for i in range(50):
    if 2 ** i <= h and h < 2 ** (i+1):
        ans = (2**i) * 2 -1
print(ans)

Solution (Python):
h=int(input())
import math
count=0
kazu=1
hp=h
while hp:
  count+=kazu
  kazu*=2
  hp=math.floor(hp/2)
print(count)

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

for i in range(10**99):
  h = h//2
  count += 2**i
  if h == 0:
    print(count)
    exit()

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

res = 0
cnt = 1
while h > 0:
    res += cnt
    h //= 2
    cnt *= 2

print(res)

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

n = int(math.log(h, 2))
ans = 2**(n+1) - 1

print(ans)

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

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

print(ans)

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

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

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

print(ans)

Solution (Python):

import sys


def solve(H: int):
    ans = 0
    tmp = 1
    while H:
        ans += tmp
        H //= 2
        tmp *= 2
    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())
def attack(x):
    if x<=1:
        return 1
    return 2*attack(x//2)+1
print(attack(H))

Solution (Python):
H=int(input())
x=1
while x<=H:
    x*=2
print(x-1)

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

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

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

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

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

Solution (Python):
h = int(input())
s = len(bin(h)) - 2
x = 0
for i in range(s):
    x += 2**i
print(x)

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




leaf = 1
while H >= 1:
    H /= 2
    leaf *= 2

print(leaf - 1)

Solution (Python):

H=int(input())
cnt=0
ans=0
while True:
    ans+=pow(2,cnt)
    cnt+=1
    if H==1:
        break
    H=int((H-H%2)/2)
print(ans)

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

Solution (Python):
H = int(input())
total = 0
for i in range(H):
  H = H//2
  total += 2**i
  if H == 0:
    break
print(total)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    H = int(input().strip())
    return H,


def solve(H):
    monsters = 1
    attacks = 0
    while H > 1:
        attacks += monsters
        H //= 2
        monsters *= 2
    attacks += monsters 
    return attacks


if __name__ == "__main__":
    inputs = read()
    print("%s" % solve(*inputs))

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

H=I()

cnt = 1

while True:
  if H == 1:
    break
  H = math.floor(H/2)
  cnt += 1
ans= 0
for i in range(cnt):
  ans += 2 ** i
  
print(ans)

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

def dist(n):
    if n == 0:
        return 0
    if n == 1:
        return 1

    ret = 2 * dist(n // 2) + 1

    return ret

print(dist(h))

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

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

print(attack(h))

Solution (Python):

H = int(input())
two_exps = []
two_exp = 2 ** 0
limit = 10 ** 12

while two_exp <= limit:
    two_exps += [two_exp]
    two_exp *= 2

for i, v in enumerate(two_exps):
    if v > H:
        print(two_exps[i - 1] * 2 - 1)
        break
else:
    print(two_exps[-1] * 2 - 1)