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:
h = int(input())
enemy_cnt = 1
ans = 0
while h:
    h //= 2
    ans += enemy_cnt
    enemy_cnt *= 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():

    H = int(input())
    count=0

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H=int(input())
def total(H):
    if H < 1:
        return 0

    return 2*total(H/2)+1
print(total(H))

Submission status: Accepted

Solution code:
# import math
# import bisect
# import heapq
# from collections import deque
# import numpy as np

# n,k = map(int, input().split())

h = int(input())
# h = list(map(int,input().split()))
ans = 0
b = 1
while h > 0:
    ans += b
    b *= 2
    h //= 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

while True:
  if 2**n<=h<2**(n+1):
    ans=sum([2**i for i in range(n+1)])
    print(ans)
    break
  else:
    n+=1

Submission status: Accepted

Solution code:
h = int(input())

c = 0
while True:
    if  2**c <= h < 2**(c+1):
        print(sum([2**n for n in range(c+1)]))
        break
    else:
        c += 1

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

Solution code:
H = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())
a=0
t=1
while H:
    H//=2
    a+=t
    t*=2
print(a)

Submission status: Accepted

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

kill = 0

for i in range(attack+1):
    kill = kill + 2**i
    #print(i,kill)

print(kill)

Submission status: Accepted

Solution code:
H = int(input())
m = 1
cnt = 0
if H == 1:
  print(1)
  exit()
while True:
  if H < m:
    print(m  - 1)
    exit()
  m *= 2
  cnt += 1

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
i, cnt = 2, 1
ans = deque([1])
while(1):
  if n<i:
    break
  ans.append(i)
  i = i*2
  
  cnt += 1
#print(ans)
print(sum(ans))

Submission status: Accepted

Solution code:
h = int(input())
def solve(result, hp):
    if hp==1:
        return result+1
    result = solve(result, hp//2)*2 + 1
    return result

print(solve(0, h))

Submission status: Accepted

Solution code:
H = int(input())

# 求める攻撃回数を関数とした再帰関数
def _attack_num(x):
    if x == 1:
        return 1
    else:
        return 2 * _attack_num(x // 2) + 1

print(_attack_num(H))

Submission status: Accepted

Solution code:
"""メモ
n = 0になるまで2で割った回数
answer = sum(2^0 + 2^1 + 2^2 + 2^3 + ... + 2^(n-1))
"""


def sum_2_expo(cnt):
    ans = 0
    for i in range(cnt):
        ans += 2 ** i
    return ans


H = int(input())
cnt = 0
while H != 0:
    H //= 2
    cnt += 1

print(sum_2_expo(cnt))

Submission status: Accepted

Solution code:
H = int(input())
count = 0
for x in range(H):
    if H < 2 ** count:
        break
    else:
        count += 1
print(2 ** count - 1)

Submission status: Accepted

Solution code:
def calc_at(H):
    # 2の0~n乗まで足す
    num = 0
    n = 0
    while True:
        n_beki2 = 2 ** n
        if H < n_beki2:
            break
        num += n_beki2
        n += 1
    return num


H = int(input())
print(calc_at(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
ans = 0
bin_h = format(h,'b')
l = len(bin_h)
for i in range(l):
    ans += 2**i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
H = int(input())
def res(H):
  if H == 1:
    return 1
  return res(int(H/2))*2+1
print(res(H))

Submission status: Accepted

Solution code:
h=int(input())
#n,k=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

import math
ans=1
count=1
while h!=1:
    count*=2
    ans+=count
    h=math.floor(h/2)
    
print(ans)

Submission status: Accepted

Solution code:
h=int(input())
for i  in range(41):
  if h<pow(2,i):
    print(pow(2,i)-1)
    break

Submission status: Accepted

Solution code:
H = int(input())


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


print(f(H))

Submission status: Accepted

Solution code:
H = int(input())

attack_num = 0
n = 0

while H >= 1:
  n += 1
  attack_num += 2 ** (n -1)
  H //= 2

print(attack_num)

Submission status: Accepted

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

H = int(input())
print(re(H))

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
import math

def get_count(H, count) :

    if (H == 1) :
        return 1


    return 2 * get_count(H // 2, count) + 1

def main() :
    H = int(input())
    c = get_count(H,0)
    print(c)

main()

Submission status: Accepted

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

Submission status: Accepted

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

if hh==1:
    print(1)
else:
    ans = 1
    for i in range(1, kaisuu+1):
        ans += 2**i
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(10**9):
  if h==1:
    cnt+=num
    break
  else:
    h=int(h/2)
    cnt+=num
    num*=2
print(cnt)

Submission status: Accepted

Solution code:
def resolve():
    import math
    h = int(input())
    logh = int(math.log(h,2))
    rlist = []
    cum = 1
    for i in range(40):
        rlist.append(cum)
        cum = cum*2+1
    print(rlist[logh])
resolve()

Submission status: Accepted

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

h = int(input())

ans = f(h)

print(ans)

Submission status: Accepted

Solution code:
import math
def main():
    h = int(input())
    cnt = 0
    ans = 0
    tmp = 1
    a = int(math.log2(h)) +1
    # cnt = 2 **a
    ans = (1-2**a)//(1-2)
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
# h = map(int, open(0).read().split())
h = int(input())


# 2
# 11
#
# 3
# 11
#
# 4
# 22
# 1111
#
# 5
# 22
# 1111
#
#
# 6
# 33
# 1111
#
# 7
# 33
# 1111
#
# 8
# 44
# 2222
# 11111111

def solve(acc, count, ans):
    if acc // 2 == 0:
        return ans + (2 ** (count - 1))

    return solve(acc // 2, count + 1, ans + (2 ** (count - 1)))


print(solve(h, 1, 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

cnt=0

def recursive(H):
    
    global cnt
    cnt=cnt+1
    if H==1:
        return
    H=int(H/2)
    
    recursive(H)
    #recursive(H)

H= int(input())

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

Submission status: Accepted

Solution code:
h = int(input())
i = 0
c = 1
while h >= c:
    c *= 2
    i += 1
i -= 1
ans = 1
x = 2
for n in range(i):
    ans += x
    x *= 2
print(ans)

Submission status: Accepted

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

print(attackcount)

Submission status: Accepted

Solution code:
h=int(input())

flag = True
vital=h
count=0

while flag:
	if vital == 1:
		flag=False
	else:
		vital = int(vital/2)
		count+=1

AAA=0

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

print(AAA)

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    H = II()
    from math import log2,floor
    print( 2**(floor(log2(H))+1)-1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H = int(input())

memo = {}
memo[1] = 1

def f(h):
    if h in memo:
        return memo[h]
    v = 2 * f(h // 2) + 1
    memo[h] = v
    return v

print(f(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
binH = list(bin(H))
binans = 0

for i in range(len(binH) - 2):
    binans += 1 * 10 ** i
    
binans = str(binans)

print(int(binans, 2))

Submission status: Accepted

Solution code:
def solve(H,i):
    if H ==1:
        return i
    else:
        return solve(H//2,i*2+1)
    
H=int(input())

ans = solve(H,1)
print(ans)

Submission status: Accepted

Solution code:
H = int(input())
K = [1]
for i in range(100):
    K.append(K[i]*2+1)
    if pow(2,i+1)>H:
        print(K[i])
        break

Submission status: Accepted

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

while h >= 1:
  count += 1
  h /= 2
print((1 << count) -1)

Submission status: Accepted

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

print(attack(int(input())))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

n = 0
while h >= 1:
    n += 1
    h /= 2
print((1 << n) - 1)

Submission status: Accepted

Solution code:
import numpy as np
def f(h):
    if h<=1:
        return 1
    else:
        return (2*f(h//2)+1)

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

Submission status: Accepted

Solution code:
def aaa(hp, times=0):
    if hp == 1:
        return times
    else:
        return aaa(hp//2, times+1)

h = int(input())
ans = 0
for i in range(aaa(h) + 1):
    ans += 2 ** i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

h = int(input())

print(caracal(h))

Submission status: Accepted

Solution code:
print(2**(len(bin(int(input()))[2:]))-1)

Submission status: Accepted

Solution code:
h = int(input())
a = 1
sum = 0

while(h > 0):
    sum += a
    a *= 2
    h = h // 2

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = 1
ans = 1
while True:
    a *= 2
    if a > n:
        break
    ans = ans*2 + 1

print(ans)

Submission status: Accepted

Solution code:

h=int(input())

for i in range(50):
    if 2**i <= h and h<2**(i+1):
        ans=i
        break
print(2**(i+1)-1)

Submission status: Accepted

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

Submission status: Accepted

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

def attack(h):
    if h == 1:
        return 1
    elif h == 2:
        return 3
    else:
        return 1 + 2 * attack(int(h/2))
ans = attack(H)
print(ans)

Submission status: Accepted

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

def main():
    H = int(input())
    ans = 0
    while H > 0:
        ans += 1
        H //= 2
    print(pow(2, ans) - 1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
print(pow(2,int(math.log(int(input()), 2)//1)+1)-1)

Submission status: Accepted

Solution code:
x=int(input())
def hit(h):
    if h==1: return 1
    elif h>1:
        return 2*hit(h//2)+1
print(hit(x))

Submission status: Accepted

Solution code:
from math import floor

h = int(input())
hSum = 0
for i in range(10**12):
    hSum += 2 ** i
    h = floor(h/2)
    if h == 0:
        break

print(hSum)

Submission status: Accepted

Solution code:
h = int(input())

i = 0
while 2**i <= h:
    i += 1

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

print(count)

Submission status: Accepted

Solution code:
#D
H = int(input())
A = 1
ans = 1
while A <= H:
    A = A * 2
    ans += A
ans -= A
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    input = stdin.readline

    H = int(input())

    ans = 0
    bai = 0

    while H >= bai*2:
        if(bai == 0):
            bai = 1
        else:
            bai = bai * 2
        ans = ans + bai
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

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

print(dfs(h))

Submission status: Accepted

Solution code:
import math

ans = {1:1}

h = int(input())

def mons(n):
  if n in ans:
    return ans[n]
  else:
    return 1+ 2*mons(math.floor(n/2))

print(mons(h))

Submission status: Accepted

Solution code:
h = input().strip()
h = int(h)
count = 0
sum = 0

while h > 0:
  h //= 2
  count += 1
  
for v in range(count):
  sum += pow(2, v)
  
print(sum)

Submission status: Accepted

Solution code:
from math import log
n=int(input())
n=2**(int(log(n,2)))
print(2*n-1)

Submission status: Accepted

Solution code:
H = int(input())

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

print(solve(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
ans = 0
count2 = 0
while H/2 == H//2:
    count2 += 1
    H //= 2
    
ans += 2**count2 - 1

###################

countOdd = 0
while H > 1:
    countOdd += 1
    H //= 2
   
ans += (2**count2) * (2**(countOdd+1) -1)

print(ans)

Submission status: Accepted

Solution code:
hp = int(input())
n_monster = 1
atk_cnt = 0
while hp > 1:
    atk_cnt += n_monster
    n_monster *= 2
    hp //= 2

atk_cnt += n_monster
print(atk_cnt)

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:


h = int(input())

if h == 1:
	h = 0
	count = 1
else:
	count = 0
	for i in range(0,100000):
		h = h//2
		#print(h)
		count += 2**i
		if h == 0:
			break

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
h = int(input())
count = 0
while h != 1:
    h = math.floor(h / 2)
    count += 1
ans = [2 ** i for i in range(count + 1)]
print(sum(ans))

Submission status: Accepted

Solution code:
h = int(input())

def count(hp):
    if hp == 1:
        return 1
    else:
        return 2 * count(int(hp/2)) + 1
print(count(h))

Submission status: Accepted

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

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

print(atack)

Submission status: Accepted

Solution code:
import math

h = int(input())

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

Submission status: Accepted

Solution code:
H = int(input())

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

print(cnt + num)

Submission status: Accepted

Solution code:
H = int(input())
i = 0
count = 0
while H > 1:
    H = H // 2
    count += pow(2, i)
    i += 1
print(count + pow(2, i))

Submission status: Accepted

Solution code:
H = int(input())

E = []

while H>0:
    E.append(H)
    H //= 2
print(pow(2, (len(E))) - 1)

Submission status: Accepted

Solution code:
h = int(input())

import math
ans = pow(2, math.floor(math.log(h, 2))+1) - 1
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

#Hは２のjo乗より小さい
i=1
while True:
    A=2**i
    if H==A:
        jo=i
        break
        
    elif H<A:
        jo=i-1
        break
    i+=1

result=0
for j in range(0,jo+1):
    result=result+2**j
print(result)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

N = int(input())

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

Submission status: Accepted

Solution code:
def calc(a):
  if a > 1:
    return 2 * calc(a // 2) + 1
  else:
    return 1

a = int(input())
i = 0
print(calc(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from collections import *
#from itertools import *
#from bisect import *
from heapq import *
#import copy
#N=int(input())
#X,Y=map(int,input().split())
#S=list(map(int,input().split()))
#S=[list(map(int,input().split())) for i in range(N)]

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

Submission status: Accepted

Solution code:
h=int(input())
d=dict()
def f(n):
  if n==1:
    return 1
  else:
    if n//2 in d.keys():
      return 1+2*d[n//2]
    else:
      return 1+2*f(n//2)
print(f(h))

Submission status: Accepted

Solution code:
import math
print(2**(math.ceil(math.log2(float(input())+1)))-1)

Submission status: Accepted

Solution code:
A = int(input())
ans = 1
while A != 0:
    A = A//2
    ans = ans * 2
    if A==0:
        ans = ans - 1
        
print(ans)

Submission status: Accepted

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

while h > 1:
    h = h//2
    #print(h)
    cnt += 1
    
if(h == 1):
    sm = 2**(cnt+1) -1
else:
    sm = 2**cnt - 1


print(sm)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

count = 0
while h > 0:
    h //= 2
    count += 1
    
n = [1]*count
for i in range(count):
    if i > 0:
        n[i] = n[i-1]*2
        
print(sum(n))

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
h = int(input())

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

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

Submission status: Accepted

Solution code:
import math

H = int(input())
max_ = math.ceil(math.log2(10**12))
dp = [1]*max_
for i in range(1,max_):
    dp[i] = dp[i-1]*2+1
print(dp[math.floor(math.log2(H))])

Submission status: Accepted

Solution code:
import numpy as np
H = int(input())
 
print(2 ** (int(np.log2(H)) + 1) - 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    dp = {}

    def execute(h):
        if h == 1:
            return 1
        if h in dp:
            return dp[h]
        ans = 1 + execute(h // 2) * 2
        dp[h] = ans
        return ans

    return execute


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

Submission status: Accepted

Solution code:
def attack(n):
    if n <= 1:
        return 1

    return 1 + attack(n // 2)*2


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

Submission status: Accepted

Solution code:
h = int(input())
ans = 0
cut = 1
while h > 0:
    ans += cut
    cut = cut << 1
    h = h >> 1
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

memo = {}
memo['0'] = 0
memo['1'] = 1

def dp(arg):
    key = str(arg)
    if memo.setdefault(key, None) != None: return memo[key]
    ret = 1 + 2 * dp(arg // 2)
    memo[key] = ret
    return ret

print(dp(H))

Submission status: Accepted

Solution code:
import math
h=int(input())
k=math.ceil(math.log2(h))
if k==math.log2(h):
  print(2**(k+1)-1)
else:
  print(2**k-1)

Submission status: Accepted

Solution code:
h = int(input())

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

print(f(h))

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]

def solve():
    return rec(N)

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

if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
def recursion(x):
    if x == 0:
        return 0
    return 1+recursion(x//2)*2

print(recursion(int(input())))

Submission status: Accepted

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(x):
	lvls = floor(log(x,2)) + 1
	ans = ((2**lvls - 1))
	return int(ans)
	

N = int(stdin.readline())
ans = solve(N)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h =int(input())

count = 0

def countMethod(n):
    global count
    if n==1:
        return

    count+=1

    countMethod(n//2)

countMethod(h)

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

Submission status: Accepted

Solution code:
H = int(input())

ans = 0
count = 0
while H != 0:
    ans += pow(2, count)
    H = H // 2
    count += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

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

H = int(input())
print(attack(H))

Submission status: Accepted

Solution code:
import math

h = int(input())
x = h
ans = 0
cnt = 0

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

print(ans)

Submission status: Accepted

Solution code:
h = int(input())

i = 1
while True:
    if h == 1:
        break
    else:
        h = h // 2
        i+=1

print(2**i-1)

Submission status: Accepted

Solution code:
#!/use/bin/env python3

import math

a = input()
#b = [int(s) for s in input().split()]

b = math.log(float(a), 2)

ans = sum([pow(2, i) for i in range(1, int(b) + 1)]) + 1

print(ans)

Submission status: Accepted

Solution code:
import sys
import math

input = sys.stdin.readline

H = int(input())

if H == 1:
    print(1)
    exit()
    
if H % 2 == 1:
    H -= 1

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

print(2**layer - 1)

Submission status: Accepted

Solution code:

def monster(X):
    global cnt
    if(X!=0):
        cnt+=1
        monster(X//2)
        




import sys
H=int(input())
cnt=0
if(H==1):
    print('1')
else:
    i=2
    j=3
    tmp=1
    while (True):
        if(i <= H and j >= H):
            print(j)
            sys.exit()
        i*=2
        j=j*2+1

Submission status: Accepted

Solution code:
H = int(input())

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

print(dfs(H))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
#L, R = map(int,input().split())
H = int(input())

h = math.ceil(math.log2(H))
if math.log2(H) == math.ceil(math.log2(H)):
  ans = pow(2,h+1)-1
else:
  ans = pow(2,h)-1
    
print(ans)

Submission status: Accepted

Solution code:
h=int(input())

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

Submission status: Accepted

Solution code:
h=int(input())
cnt=0
while h>1:
	if h%2==0:
		cnt+=1
		h/=2
	else:
		h-=1
num=[2**i for i in range(cnt+1)]
print(sum(num))

Submission status: Accepted

Solution code:
def find(x):
    if x==1:
        return 1
    if x==0:
        return 0
    y=x//2
    return  1+2*find(y)
    
print(find(int(input())))

Submission status: Accepted

Solution code:
h=int(input())
s=[2**i-1 for i in range(1,100)]
tmp=[2**i for i in range(100)]

for i in range(100):
  if tmp[i]>h:
    print(s[i-1])
    break

Submission status: Accepted

Solution code:
def slove(h,counter):
    if h == 1:
        return counter + 1
    else:
        return 2 * slove(h//2,counter) + 1

h = int(input())

print(slove(h,0))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15


def main():
    n = getN()
    po = 1
    while(n > 1):
        po += 1
        n = n//2

    print(2**po - 1)


if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Submission status: Accepted

Solution code:
H = int(input())
n = len(bin(H)) - 3
N = [2 ** i for i in range(n + 1)]
print(sum(N))

Submission status: Accepted

Solution code:
import math

H = int(input())

log2H = int(math.log2(H))

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

Submission status: Accepted

Solution code:
h=int(input())

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

print(cnt(h))

Submission status: Accepted

Solution code:
H = int(input())
cnt = 0
num_monster = 1

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

cnt += num_monster

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())


def f(X):
    if X < 2:
        return X
    return f(int(X / 2)) * 2 + 1


print(f(H))

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:

h = int(input())
ans =0
mos = []
i = 1
while h > 0:
    mos.append(i)
    h = h//2
    i *=2
    
    
print(sum(mos))

Submission status: Accepted

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

for i in range(1, h):
    ans += 2 ** i
    h = h // 2
    if h == 1:
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = input()
cache = {1:1}
def foo(h):
    if h not in cache:
        cache[h] = 1 + foo(h/2) * 2
    return cache[h]

print foo(h)

Submission status: Accepted

Solution code:
import numpy
h=int(input())
p=int(numpy.log2(h))
print(2**(p+1)-1)

Submission status: Accepted

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

#2で割れる回数が同じなら同じ結果　ex)4,5,6,7は2**3-1回必要
while h >= 2:
    h //= 2
    count += 1

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

#攻撃の順番は気にしなくていい

#2の40乗までのリスト
s = [0]
for i in range(41):
    s[i] = 2**i
    s.append(s[i])

#2の何乗の間にあるかがわかればよい
for i in range(41):
    if h >= s[i]:
        ans += s[i]
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
H = int(input())
e = 1
h = H
while h != 1:
    h = h // 2
    e += 1

print(2 ** e - 1)

Submission status: Accepted

Solution code:
def f(H):
    if H == 1:
        return 1
    if H > 0:
        return 2 * f(int(H/2)) + 1

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