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



Sample input:
2


Sample output:
3

Submission status: Accepted

Solution code:
"""
NTC here
"""
import sys
inp= sys.stdin.readline
input = lambda : inp().strip()
flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**25)

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

# range = xrange
# input = raw_input


def main():
    h = iin()
    ans = 0
    ch, ch1 = h, 1
    while ch*ch1 :
        ch //= 2
        ans += ch1
        ch1 *= 2

    print(ans)



            
        

        
main()
# threading.Thread(target=main).start()

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

H=II()

cntEnem = 1
cntAtk = 0

while H:
    cntAtk += cntEnem
    cntEnem *= 2
    H //= 2

print(cntAtk)

Submission status: Accepted

Solution code:
h = int(input())

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

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

Submission status: Accepted

Solution code:
h = int(input())
cnt = 0
while h > 0:
  h = h // 2
  cnt = cnt + 1
     
print(int(pow(2, cnt) - 1))

Submission status: Accepted

Solution code:
H = int(input())
times = 0
ans = 0

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

Submission status: Accepted

Solution code:
h=int(input())
import sys
sys.setrecursionlimit(10**5)
def ans(x):
    if x <= 1:
        return 1
    else:
        return ans(x//2)*2+1
print(ans(h))

Submission status: Accepted

Solution code:
H = int(input())
now = 1
while now <= H:
    now *= 2
print(now - 1)

Submission status: Accepted

Solution code:
h = int(input())
if h == 1:
    print(1)
    exit()
for i in range(1,2000):
    h //= 2
    if h == 1:break
ans = 2**(i+1)-1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#  --*-coding:utf-8-*--

H = int(input())

x = 0
a = 1

while H>0:
    x += a
    a *= 2
    H //= 2

print(x)

Submission status: Accepted

Solution code:
import math

h = int(input())
memo = [0]
cnt = 0

while h > 1:
    cnt += 1
    memo.append(cnt)
    h = math.floor(h / 2)

ans = 0
for i in range(len(memo)):
    ans += 2 ** memo[i]

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
#from collections import deque
#from math import ceil


def ii(): return int(stdin.readline())


def fi(): return float(stdin.readline())


def mi(): return map(int, stdin.readline().split())


def fmi(): return map(float, stdin.readline().split())


def li(): return list(mi())


def lsi():
    x=list(stdin.readline())
    x.pop()
    return x


def si(): return stdin.readline()


def sieve(x):
    a=[True]*(x+1)
    sq=floor(sqrt(x))
    for i in range(3, sq+1, 2):
        if a[i]:
            for j in range(i*i, x+1, i):
                a[j]=False
    if x>1:
        p=[2]
    else:
        p=[]
    for i in range(3, x+1, 2):
        if a[i]:
            p.append(i)
    return p
#vowel={'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y'}
pow=[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, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808]
############# CODE STARTS HERE #############
n=ii()
p=0
for i in pow:
    if i>n:
        break
    p+=i
print(p)

Submission status: Accepted

Solution code:
h=int(input())
r=h
x=0
while h>1:
  h/=2
  x+=1
if r%(2**x)==0:
  ans=2**(x+1)-1
else:
  ans=2**x-1

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

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

ans = solve(H)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

a = bin(h)
b = len(a)-2

print(2**b - 1)

Submission status: Accepted

Solution code:
h = int(input())

checked = {}


def check_attack(h):
    if h == 1:
        checked[h] = 1
        return 1
    elif h in checked:
        return checked[h]
    else:
        k = 1 + 2 * check_attack(h//2)
        checked[h] = k
        return k

print(check_attack(h))

Submission status: Accepted

Solution code:
h = int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
n = bin(n)

ans = 0
for i in range(len(n[2:])):
    ans += 2 ** i
    
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

import numpy as np

def solve(num):

    if num==1:
        return 1

    return 1+2 * solve(np.floor(num/2))

print(solve(h))

Submission status: Accepted

Solution code:
def bfs(hp):
    if hp == 1:
        return 1
    else:
        return 1 + 2 * bfs(hp//2)

h = int(input())
print(bfs(h))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# from math import log2

H = int(input())

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


print(attack(H))

Submission status: Accepted

Solution code:
H = int(input())

H += 1
tmp = 1
ans = 0
i = 0
while H > tmp:
    tmp *= 2
    ans += 2**i
    i += 1
print(ans)

Submission status: Accepted

Solution code:
#N, K = [int(i) for i in input().split()]
#Hn = [int(i) for i in input().split()]

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

H = int(input())

count = attack(H)
print(count)

Submission status: Accepted

Solution code:
h=int(input())
n=len(bin(h))-2
ans=0
for i in range(n):
    ans+=2**i
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
H = int(input())

q = deque()
q.append(H)
ans = 0
h = H
K = 0
while h > 1:
    h //= 2
    K += 1

print(sum([2 ** k for k in range(K + 1)]))

Submission status: Accepted

Solution code:
H = int(input())
#N,K,M= map(int,input().split())
#A =list(map(int,input().split()))
#L = [list(map(str,input().split())) for i in range(N)]
h = H
count = 0
while h:
    h = h//2
    count += 1

print(2**count-1)

Submission status: Accepted

Solution code:
H = int(input())
i = 0
while 2**i < H:
  i += 1
if 2**i != H:
  i -= 1
ans = 0
j = 0
while j <= i:
  ans += 2**j
  j += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    H = int(input())

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

    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
h = int(input())

flag = False
n = 0

while flag == False:
    if 2**n <= h < 2**(n+1):
        flag = True
    else:
        n += 1
print(2**(n+1)-1)

Submission status: Accepted

Solution code:
h = int(input())
count = 0
while h > 0:
    count += 1
    h //= 2

print(sum(2**i for i in range(count)))

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

H = int(input())
k = 0

for i in range(40+1):
    a = 2**i
    if H<a:
        k = i - 1
        break
cnt = 0
for i in range(k+1):
    cnt += 2**i
print(cnt)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False

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

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
H = int(input())
count = 1
i = 1

while H > 1:
    H = math.floor(H/2)
    count += 2**i
    i += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

count = 1
ans = 0

while h != 0:
    ans += count
    h = h//2
    count *=2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())

N=100
p=[1]*(N+1)
for i in range(N):
    p[i+1]=p[i]*2
    
index=0
for i in range(N):
    if H==p[1]:
        index=i
    if H<p[i]:
        index=i-1
        break
        
print(p[index+1]-1)

Submission status: Accepted

Solution code:
from math import log, floor
H = int(input())
f = floor(log(H, 2))

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

Submission status: Accepted

Solution code:
from functools import lru_cache

@lru_cache(None)
def rec(n):
    if n == 1:return 1
    if n == 0:return 0
    
    return 1 + 2*rec(n//2)
    
    

def main():
    h = int(input())
    print(rec(h))
    
    
    
    
    
    
    
main()

Submission status: Accepted

Solution code:
def cara(n):
    if n < 2:
        return 1
    else:
        return (1 + (2 * cara(n // 2)))


h = int(input())

print(cara(h))

Submission status: Accepted

Solution code:
h=int(input())
cnt=0
ans=0
while h!=1:
    h=h//2
    cnt+=1
print(2**(cnt+1)-1)

Submission status: Accepted

Solution code:
H = int(input())
from math import log, floor
a = log(H, 2)
a = floor(a) + 1
print(2**a-1)

Submission status: Accepted

Solution code:
''' Hey stalker :) '''
INF = 10**10
def main():
    print = out.append
    ''' Cook your dish here! '''
    h = get_int()
    print((1<<h.bit_length()) - 1)




''' Pythonista fLite 1.1 '''
import sys
#from collections import defaultdict, Counter
#from bisect import bisect_left, bisect_right
#from functools import reduce
#import math
#input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')

Submission status: Accepted

Solution code:
H = int(input())
k = 0

while H != 1:
  H = H//2
  k += 1

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

Submission status: Accepted

Solution code:
h = int(input())
now = 1
c = 1
while(h!=1):
  h = h//2
  now *= 2
  c += now
print(c)

Submission status: Accepted

Solution code:
h=int(input())
ans=0
count=1
while(True):
  if h==1:break
  count+=1
  h=h//2
for i in range(count):
  ans+=2**i
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0
index = 0

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

print(cnt)

Submission status: Accepted

Solution code:
h = int(input())

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

print(2 ** cnt - 1)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
tmp = 1
while (n):
    ans += tmp
    tmp *= 2
    n //= 2

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def memodict(f):
    """ Memoization decorator for a function taking a single argument. """
    class memodict(dict):
        def __missing__(self, key):
            ret = self[key] = f(key)
            return ret

    return memodict().__getitem__


@memodict
def solve(x):
    if x == 1:
        return 1
    return 2 * solve(x // 2) + 1


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


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

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


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        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")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
h = int(input())
count = 0
ans = 0
while h > 0:
    if h == 1:
        h = 0
    else:
        h = math.ceil(h // 2)
    ans += 2 ** count
    count += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
input=sys.stdin.readline


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

Submission status: Accepted

Solution code:
from functools import lru_cache
import sys
sys.setrecursionlimit(10000000)
@lru_cache(maxsize= 10 ** 7)
def solve(n):
  if n == 1:
    return 1
  else:
    return solve(n//2) * 2 + 1
h = int(input())
print(solve(h))

Submission status: Accepted

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

sou = int(math.log2(h))


ans = 1 + (2**(sou)-2)/(2-1) + 2**(sou)

print(int(ans))

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    H = INT()
    count = 0
    # x = 2
    while H != 1:
        H = H // 2
        count += 1
    print(2 ** (count) * 2 - 1)
    # print(count)
    # while x < H:
    #     x = x * 2
    #     count += 1
    # print(count)




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline

h=int(input().rstrip())
cnt,ans=1,0
while h>1:
    h//=2
    ans+=cnt
    cnt*=2
    #print(h,cnt,ans)
print(ans+cnt)

Submission status: Accepted

Solution code:
h = int(input())

n = 1
result = 0
while h:
    result += n
    if h == 1:
        break
    h //= 2
    n *= 2

print(result)

Submission status: Accepted

Solution code:
H = int(input())
c = 1
while H > 0:
  c *= 2
  H //= 2

print(c-1)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
H = int(input())
L = len(bin(H)) - 2
print(2**L - 1)

Submission status: Accepted

Solution code:
from math import log2
h = int(input())

num = int(log2(h))
ans = 0
for i in range(1, num+1):
    ans += 2 ** i
print(1+ans)

Submission status: Accepted

Solution code:
x = int(input())
bin_str = format(x, 'b')
ketasuu = len(bin_str)
print(2 ** ketasuu - 1)

Submission status: Accepted

Solution code:
H = int(input())
n = 1
h = H
while True:
    if h == 1:
        break
    n *= 2
    h = h//2

print(n*2-1)

Submission status: Accepted

Solution code:
h = int(input())

count = 0

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

Submission status: Accepted

Solution code:
H=int(input())
ans=0
m_count=1
cur_hp=H
while cur_hp>0:
    if cur_hp==1:
        ans+=m_count
        break
    else:
        ans+=m_count
        cur_hp//=2
        m_count*=2
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

if h == 1:
    print(1)
    exit()

ans = 1
add = 2
while ans < h:
    ans += add
    add *= 2
    
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    h = int(args[0])
    return str((1 << len(format(h, 'b'))) - 1)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

Solution code:
H = int(input())

twos = [2 ** i for i in range(41)]

for val in twos:
    if H < val:
        print(val-1)
        break

Submission status: Accepted

Solution code:
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect
import heapq


MOD = 1000000007


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    # N, K = get_inputs(int)
    # H = get_inputs(int)

    # if K >= N:
    #     print(0)
    # else:
    #     # K < N
    #     print(sum(sorted(H)[:N-K]))

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import log

H = int(input())

print(sum(
    2 ** i
    for i in range(int(log(H, 2)) + 1)
))

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

h = ni()
c = 1
ans = 0
while h:
    ans += c
    c <<= 1
    h >>= 1
print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8

def main():
    h = int(input())
    n = 0
    cnt = 0
    while h > 0:
        h //= 2
        cnt += 2**n
        n += 1
    print(cnt)
    
main()

Submission status: Accepted

Solution code:
h = int(input())
def pow(n, p): #繰り返し二乗法
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2
            p //= 2
        else:
            res = res * n
            p -= 1
    return res

for i in range(1,10*100):
    if h < pow(2,i):
        p = i-1
        break
ans = 0
for i in range(p+1):
    ans += 2**i
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

h=INT()
cnt=0
while h>1:
    #print(h//2)
    cnt+=1
    h//=2
#print("cnt",cnt)

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

Submission status: Accepted

Solution code:
#D
H=int(input())
memo=[0]*(10**7)
memo[1],memo[2]=1,3
def atk(N):
    if N>10**6:
        return 2*atk(N//2)+1
    else:
        if memo[N]==0:
            memo[N]=2*atk(N//2)+1
        return memo[N]
    
print(atk(H))

Submission status: Accepted

Solution code:
h = int(input())
n = len(bin(h)) - 2
print(2**n - 1)

Submission status: Accepted

Solution code:
H = int(input())
bin_num = format(H, 'b')
ans = 2**(len(bin_num))-1
print(ans)

Submission status: Accepted

Solution code:
import math
import sys
sys.setrecursionlimit(10 ** 6)


def solve(n):
    if n == 1:
        return 1
    return 1 + 2 * solve(math.floor(n / 2))

H = int(input())
print(solve(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
H=int(input())

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

print(sai(H))

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
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
 

 
#main
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)

Submission status: Accepted

Solution code:
#!/bin/bash
''':'
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)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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

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


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
h=int(input())

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)