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:
def attack(num, cnt):
    cnt+=1
    if num==1:
        return cnt
    else:
        return attack(num//2, cnt)

    
H = int(input())
cnt=0
cnt = attack(H, cnt)
tmp = [2**x for x in range(cnt)]
print(sum(tmp))

Submission status: Accepted

Solution code:
h = int(input())
attack_counter = 1

while h >= 1:
    h //= 2
    attack_counter *= 2

print(attack_counter + h - 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

from collections import deque

d = deque([H])

count = 0
sm = 0
while 1:
    if H == 1:
        break

    H //= 2
    count += 1
    sm += 2**count

print(sm+1)

Submission status: Accepted

Solution code:
import math
H = int(input())
n = math.floor(math.log(H, 2))
c = 1
for i in range(n):
    c += (2 ** (i+1))
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
H = int(input())
D = {1: 1}


def dfs(H):
    if H in D:
        return D[H]

    D[H] = dfs(H//2) + dfs(H//2) + 1
    return D[H]


print(dfs(H))

Submission status: Accepted

Solution code:
n = int(input())

counter = 0

while n > 0:
  n = n//2
  counter += 1
  
counter = 2**counter-1

print(counter)

Submission status: Accepted

Solution code:
# ABC153-D
H=int(input())
cnt=1
ans=0
while H>1:
    ans+=cnt
    H//=2
    cnt*=2
print(ans+cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = int(input())
def a(n):
    if n == 1:
        return 1
    else:
        return 2 * a(n // 2) + 1
print(a(x))

Submission status: Accepted

Solution code:
h = int(input())

ans = 0
cnt = 0

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

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  h = int(readline())
  def attack(x):
    if x==1:
      return 1
    else:
      x = x//2
      return 1+2*attack(x)
  print(attack(h))
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

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

print(f(int(input())))

Submission status: Accepted

Solution code:
h = int(input())
n = 0
while h != 0:
    if h == 1:
        n += 1
        break
    h = h // 2
    n += 1
a = [2 ** i for i in range(n)]
print(sum(a))

Submission status: Accepted

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

count = 0
while True:
    count += 1
    if h == 1:
        break
    else:
        h = math.floor(h/2)

print(pow(2, count)-1)

Submission status: Accepted

Solution code:
h=int(input())
num=1
while 2**num<=h:
  num+=1
print(2**num-1)

Submission status: Accepted

Solution code:
mod = 10**9 + 7

def main():
    H = iip(listed=False)
    N = 1

    ret = 0
    while True:
        ret += N
        if H == 1:
            break
        else:
            H //= 2
            N *= 2
    print(ret)


#####################################################ライブラリ集ここから

def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    while r-l > 1:
        x = (l+r)//2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        return r
    if side == "right":
        return l+1



def iip(listed):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H=int(input())
def count(H):
  s=1
  c=1
  while H!=1:
    H=H//2
    c*=2
    s+=c
  return s
print(count(H))

Submission status: Accepted

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

while H>0:
    ans=ans*2
    H=H//2#新敵の残りHP
    ans+=1

print(ans)

Submission status: Accepted

Solution code:
def a(x):
    if x == 1: return 1
    if x > 1: return a(x // 2) * 2 + 1

print(a(int(input())))

Submission status: Accepted

Solution code:
def resolve():
    H = int(input())
    def sol(n):
        if n == 1:
            return 1
        return 1 + 2 * sol(n//2)
    print(sol(H))

resolve()

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

h = ii()
count = 0
ans = 1
while h >= 2:
    h = h//2
    ans += 2*count
    count += 1
#print(ans,count)
if count == 0:
    print(1)
else:
    print(2**(count+1)-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n =int(input())
ans = 1
for i in range(int(np.log2(n))):
    ans += 2**(i+1)
    
print(ans)

Submission status: Accepted

Solution code:
h=int(input())

ans=0
p=0
for i in range(41):
    n=2**i
    if h<n:
        p=2**(i-1)
        break

print(2*p-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

print(dev_(h))

Submission status: Accepted

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

h=int(input())

print(attack(h))

Submission status: Accepted

Solution code:
import math
h = int(input())
print(math.ceil(2**(int(math.log(h, 2))+1)-1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(H: int):
    def dfs(H):
        if H == 1:
            return 1
        else:
            return 2*dfs(H//2)+1
    print(dfs(H))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    solve(H)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
a=0
d=1
while d<=N:
  a+=d
  d*=2
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def slove(H):
    if H==1:
        return 1
    else:
        return 2*slove(H//2)+1
H=int(input())
print(slove(H))

Submission status: Accepted

Solution code:
global counter
counter=0
def slove(H):
    if H==1:
        return 1
    else:
        return 2*slove(H//2)+1
H=int(input())
print(slove(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache
@lru_cache(maxsize=None)
def alg_memoization_recursion(n):
    if n==1:
        return 1
    else:
        return alg_memoization_recursion(n//2) + alg_memoization_recursion(n//2) + 1

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
h = int(input())
print(2 ** (h.bit_length()) -1)

Submission status: Accepted

Solution code:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/D-CaracalVsMonster.py
#
import math

h = int(input())
double_by_attack = int(1)
trial_of_attack = int(0)


for i in range(h):
    if h > 1:
        trial_of_attack = trial_of_attack + double_by_attack
        double_by_attack = double_by_attack * 2
        h = math.floor(h/2)
    else:
        trial_of_attack = trial_of_attack + double_by_attack
        print(trial_of_attack)
        break

Submission status: Accepted

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

a = int(math.log(H,2))

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

Submission status: Accepted

Solution code:
N = int(input())
cnt = 0

while N>1:
    N = int(N/2)
    cnt +=1

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

Submission status: Accepted

Solution code:
H = int(input())
ans = 0
monsterno = 1

while H > 1:
    ans += monsterno
    H //= 2
    monsterno *= 2

print(ans+monsterno)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
i = h
x = 0

while h >= 2:
  h = h / 2
  x = x + 1 #2のなんじょうかを求める

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

Submission status: Accepted

Solution code:
h = int(input())
cnt = 0
ans = 1

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

Submission status: Accepted

Solution code:
H = int(input())

n = 0
H_bin = bin(H)
length = len(H_bin) - 2

ans_bin = "0b"
for _ in range(length):
    ans_bin += "1"

print(int(ans_bin, 2))

Submission status: Accepted

Solution code:
H = int(input())
ans = 0
num = 1
A = [1]
for i in range(100):
  if H / 2 < 1:
    ans += 1
    break
  else:
    H = H / 2
    ans += 1
for j in range(ans-1):
  A.append(num*2)
  num = num*2
print(sum(A))

Submission status: Accepted

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

    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
dep = 0
def log_num(n):
    global dep
    if n == 1:
        return dep
    else:
        dep += 1
        log_num(n//2)
log_num(h)
ans = 1
for i in range(dep+1):
    ans *= 2
print(ans-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math

H = int(input())
N = math.floor(math.log(H,2))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
hp = int(input())
ans = 0
cnt = 0
if (hp == 1):
    print (1)
else:
    while (hp > 0):
        hp = hp // 2
        ans += 2 ** cnt
        cnt += 1
    print (ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

x = sys.stdin.readline()
h = int(x)

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

count = dp(h)
print(count)

sys.stdout.flush()

Submission status: Accepted

Solution code:
N = int(input())

q = N
cnt = 0

while (q > 1) :
    q = q // 2
    cnt += 1

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

Submission status: Accepted

Solution code:
h = int (input ())

cnt = 0
while (h >> 1) :
    cnt += 1
    h >>= 1

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

print (ans)

Submission status: Accepted

Solution code:
# 初期入力
H = int(input())

#モンスター１匹ずつは考えない、１ターンでHが半分、モンスターの数２倍
kougeki_kaisu = [1]
monster_num =1

while 1 < H:
    H = H // 2
    monster_num = monster_num * 2
    kougeki_kaisu.append(monster_num)
    # print(H,kougeki_kaisu)
# print(H,kougeki_kaisu)
print(sum(kougeki_kaisu))

Submission status: Accepted

Solution code:
H = int(input())
count=1
while H>1:
    H=H//2
    #print(H)
    count+=1
#print(count)
total=0
for i in range(count):
    total+=2**i
print(total)

Submission status: Accepted

Solution code:
H = int(input())
num = 1
attack = 1
while H > 1:
  H = H // 2
  num *= 2
  attack += num  
print(attack)

Submission status: Accepted

Solution code:
H=int(input())
cnt=0
i=0
while True:
  H=H//2
  cnt+=pow(2,i)
  i+=1
  if H==0:
    break
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

hp = int(input())
print(attack(hp))

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())
if h==1:
    print(1)
    exit()
a=1
while h>1:
    h//=2
    a+=1
print(2**a-1)

Submission status: Accepted

Solution code:
x = int(input())

import math

print((2**(math.floor(math.log2(x))+1))-1)

Submission status: Accepted

Solution code:
# A = [list(map(int, input().split())) for _ in range(3)]
H = int(input())
# B = [int(input()) for _ in range(n)]
# A = list(map(int, input().split()))
# a, b = map(int, input().split())
# S = input()


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


print(f(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

print(f(H))

Submission status: Accepted

Solution code:
import math

h = int(input())

count = 0
while True:
    if h == 1:
        break
    h = int(h / 2)
    count += 1
print(pow(2, count + 1) - 1)
exit(0)


l = math.log(h + 1, 2)
print(pow(2, math.ceil(l)) - 1)

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

print(att(n))

Submission status: Accepted

Solution code:
h=int(input())
s=0
i=1
while h>=i:
    s+=i
    i*=2
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
import math
import string

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

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

print(ans)

Submission status: Accepted

Solution code:
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:23/03/2020
'''


from math import ceil
def main():
    
    
    
    
    
    
    
    
    
    
    
    ans=0
    n=int(input())
    if(n==1):
        print('1')
    elif(n==2 or n==3):
        print('3')
    else:
        ans=0
        c=1
        while(n>3):
            ans+=c
            c*=2
            n//=2
        ans+=(3*c)
        print(ans)
    
    
    
    
    
    
    
    
    
if __name__ =="__main__":
    main()

Submission status: Accepted

Solution code:

h = int(input())

def calc_ans(h, n):
    if h == 1:
        return 2 ** n
    else:
        return 2 ** n + calc_ans(h // 2, n + 1)
print(calc_ans(h, 0))

Submission status: Accepted

Solution code:
n=int(input())
hoge=bin(n)
hoge=hoge[::-1]
ans=0
atk=0
for i in range(len(hoge)-2):
  atk=1+atk*2
  ans=atk*int(hoge[i])
  
print(ans)

Submission status: Accepted

Solution code:
h=int(input())

a=0
i=0
while a<h:
    a+=2**i
    i+=1
print(a)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
h = int(input())
if(h == 1):
  print(1)
  exit()
cnt = 1
point = 0
list = [0 for i in range(100)]
while (h>point+1):
  list[cnt] = ((list[cnt-1] * 2) +1)
  point += 2**cnt
  cnt += 1

print(list[cnt-1]*2+1)

Submission status: Accepted

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

while True:
    if H < 2**i:
        print(2**i-1)
        sys.exit()
    i += 1

Submission status: Accepted

Solution code:
import sys
H=int(input())
numlist = []
i = 1
if H == 1:
    print('1')
    sys.exit()

while True:
    if H < 2**i:
        print(2**i-1)
        sys.exit()
    i += 1

Submission status: Accepted

Solution code:
import sys
H=int(input())
numlist = []
i = 1
if H == 1:
    print('1')
    sys.exit()

while True:
    tmp = 2**i
    numlist.append(tmp)
    i += 1
    if tmp >= 1000000000000:
        break

for i in range(1,len(numlist)):
    if H < numlist[i]:
        print(numlist[i-1]*2-1)
        sys.exit()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000) #REしたら増やす
from functools import lru_cache
@lru_cache(maxsize=1000) #いじらなくてよい

def atack(H):
    if H == 1:
        return 1
    return 2*atack(H//2) + 1
    
H = int(input())
print(atack(H))

Submission status: Accepted

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



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def gausu(x):
    if x%2==0:
        return int(x/2)
    if x%2==1:
        return int((x-1)/2)
h=int(input())
i=0
while h!=1:
    h=gausu(h)
    i=i+1
#print(i)
answer=2**(i+1)-1
print(answer)

Submission status: Accepted

Solution code:
H=int(input())
print(2**(H.bit_length())-1)

Submission status: Accepted

Solution code:
h = int(input())

cnt = 0
num_monster = 1

while True:
    if h == 1:
        cnt += num_monster
        break
    else:
        cnt += num_monster
        num_monster *= 2
        h = int(h / 2)

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
n = 0
while H//2 != 0:
    H = H//2
    n += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())
num=0
while h//2!=0:
    h//=2
    num+=1

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

Submission status: Accepted

Solution code:
import math
 
n = int(input())
kaisu = math.log2(n) + 1
ans = 0
 
for i in range(int(kaisu)):
  ans += 2 ** i
 
print(ans)

Submission status: Accepted

Solution code:
import math

h = int(input())

#第一項……全モンスターの体力を1にするために必要な攻撃数
#第二項……体力が1のモンスターの数
#math.floor(math.log(h,2))は体力を1にするために必要なステップ数
print((1-2**math.floor(math.log(h,2)))//(1-2)+2**math.floor(math.log(h,2)))

Submission status: Accepted

Solution code:
import math

h = int(input())

print((1-2**math.floor(math.log(h,2)))//(1-2)+2**math.floor(math.log(h,2)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
def f(n):
    if n == 1:
        return 1
    else:
        x = n//2
        time = 2 * f(x) + 1
        return time

print(f(n))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)

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

h = int(input())

ans = attack(h)

print(ans)

Submission status: Accepted

Solution code:
#153_D
h = int(input())

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

Submission status: Accepted

Solution code:
h = int(input())
def attack(h):
    if h == 1:
        return 1
    else:
        return 1 + attack(h // 2)* 2

print(attack(h))

Submission status: Accepted

Solution code:
import math
h = int(input())
print(pow(2, 1+math.floor(math.log2(h)))-1)

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
H = int(input())
ans = 0
ms = [(H, 1)]
while ms:
  m, c = ms.pop()
  ans += c
  if m > 1:
    ms.append((m // 2, c * 2))
print(ans)

Submission status: Accepted

Solution code:
H = int(input())
ans = 0
ms = [(H, 1)]
while ms:
    m, c = ms.pop()
    ans += c
    if m > 1:
        ms.append((m // 2, c * 2))
print(ans)

Submission status: Accepted

Solution code:
from math import log2
H = int(input())
c = int(log2(H))
ans = (1 << (c + 1)) - 1
print(ans)

Submission status: Accepted

Solution code:
H = int(input())
 
 
def main(H):
  if H == 1:
    return 1
  else:
    return main(H//2)*2 + 1
 
if __name__=='__main__':
  print(main(H))

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

Solution code:
import math

h = int(input())
n = math.floor(math.log(h, 2))
print(2**(n+1)-1)

Submission status: Accepted

Solution code:
from functools import lru_cache

@lru_cache(maxsize=None)
def attack(x):
    if x == 1:
        return 1
    nxt = x // 2
    return 1 + 2 * attack(nxt)


def submit():
    h = int(input())
    print(attack(h))


if __name__ == "__main__":
    submit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
cnt = 1
while True:
  if n == 1:
    break
  else:
    n = n//2
    cnt += 1
  
print(2**cnt - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

count = 0
m = 1
while h:
    if h == 1:
        count += m
        h = 0
    else:
        h = h//2
        count += m
        m *= 2

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    
    h = int(input())
    
    tmp = 0
    while h != 0:
        h = h//2
        tmp += 1

    print(2**tmp-1)
    
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

H = int(input())
if H == 1:
    print(1)
else:
    height = int(math.log2(H))
    print(2 * (2 ** height) - 1)

Submission status: Accepted

Solution code:
h = int(input())

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

print(ans(h))

Submission status: Accepted

Solution code:
import sys

H=int(input())
M=[]

for i in range(41):
   M.append(2**i)

for i in range(41):
    if H<M[i]:
        print(M[i]-1)
        sys.exit()

Submission status: Accepted

Solution code:
H=int(input())
number=1
numbers=[]
while number<pow(10,12):
    numbers.append(number)
    number*=2
numbers=[a for a in numbers if a <=H]
print(sum(numbers))

Submission status: Accepted

Solution code:
def bin(n):
  k = 0
  while(n >= 2**k):
    k += 1
  return 2**k-1
H = int(input())
print(bin(H))

Submission status: Accepted

Solution code:
h = int(input())
mon_num = 1
count = 1
while True:
    if h <= 1:
        break
    else:
        h //= 2
        mon_num *= 2
        count += mon_num
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def s(d, i=1, a=1):
    a += i*2
    if d <= 1:
        return a
    return s(d-1,i=i*2, a=a)

H = int(input())
if H==1:
    print(1)
    sys.exit()
count = 0

while True:
    count += 1
    
    H = H // 2
    
    if H <= 1:
        break

print(s(count))

Submission status: Accepted

Solution code:
n = int(input())
for i in reversed(range(40)):
    if n >= 2 **i:
        print(2**(i+1)-1)
        break

Submission status: Accepted

Solution code:
def hel(h):
  if h==1:
    return 1
  else:
    return (2*hel(int(h/2))+1)
health=int(input())
print(hel(health))

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

ans = dfs(H)
print(ans)

Submission status: Accepted

Solution code:
H=int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
H = int(input())

def attackNum(H):
    if H == 1:
        return 1
    else:
        return 2 * attackNum(H // 2) + 1

print(attackNum(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(H: int):
    from math import ceil
    from functools import lru_cache

    @lru_cache(None)
    def f(n: int):
        if 0 < n <= 1:
            return 1
        
        return 1 + f((n//2)) + f((n//2))

    print(f(H))
    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))  # type: int
    solve(H)

if __name__ == '__main__':
    main()