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: Time Limit Exceeded

Solution code:
from math import floor	# 切り下げ
h = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
from math import floor	# 切り下げ
h = int(input())
cnt = 0
def attack(hp):
  if hp == 1:
    global cnt
    cnt += 1
    return
  else:
    hp = floor(hp/2)
    global cnt
    cnt += 1
    attack(hp)
    attack(hp)

attack(h)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
count = 0
def count_buttle(h):
    global count
    if h == 1:
        count += 1
        return
    h = h//2
    count += 1
    count_buttle(h)
    count_buttle(h)
H = int(input())
count_buttle(H)
print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
tairyoku = int(input())
total = []
total.append(tairyoku)
count = 0
while(True):
  if len(total) == 0:
    print(count)
    break
  elif total[0] == 1:
    total.pop(0)
    count += 1
  else:
    half = math.floor(total.pop(0)/2)
    total.extend([half,half])
    count += 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
count=0
s=1
while True:
  if a!=1:
    a=a//2
    count+=1
    s+=2**count
  else:
    s+=2**count

Submission status: Time Limit Exceeded

Solution code:
N=int(input())


def monum(H):
    if H==1:
        return 1
    else:
        return 1+monum(H//2)+monum(H//2)
print(monum(N))

Submission status: Time Limit Exceeded

Solution code:
h = int(input())

log = {'1': 1 , '2': 3, '3': 3, '4': 7 }
i = 1
for i in range(1, h+1, 1):
    if not (str(i) in log):
        n = i // 2
        log.setdefault(str(i), log[str(n)]*2 +1)
        ##print("N(" + str(i)+ "):" + str(log[str(i)]))

print(log[str(h)])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
h = int(input())

log = {'1': 1 , '2': 3, '3': 3, '4': 7 }

i = 1
while i <= h:
  if str(i) in log:
    hoge = 1
    # print(log[str(i)])
  else:
    n = i // 2
    log.setdefault(str(i), log[str(n)]*2 +1)
    # print(log[str(i)])
  i=i+1
print(log[str(h)])

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

cnt = H
B = [H]

for i in range(100000000000):
    cnt = cnt//2
    B.append(cnt)
    if cnt == 1:
        break

C =[1]
for i in range(1,1001):
    C.append(C[i-1]*2)

#print(len(C))
ans= 0
for i in range(len(B)):
    ans +=C[i]

if H == 1:
    print('0')
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

cnt = H
B = [H]
for i in range(100000000000):
    cnt = cnt//2
    B.append(cnt)
    if cnt == 1:
        break

C =[1]
for i in range(1,1001):
    C.append(C[i-1]*2)

#print(len(C))
ans= 0
for i in range(len(B)):
    ans +=C[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

cnt = H
B = [H]
for i in range(100000000000):
    cnt = cnt//2
    B.append(cnt)
    if cnt == 1:
        break

C =[1]
for i in range(1,100):
    C.append(C[i-1]*2)

ans= 0
for i in range(len(B)):
    ans +=C[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

cnt = H
B = [H]
for i in range(100000000000):
    cnt = cnt//2
    B.append(cnt)
    if cnt == 1:
        break

C =[1]
for i in range(1,1000):
    C.append(C[i-1]*2)

ans= 0
for i in range(len(B)):
    ans +=C[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

# i = format(n, 'b')[::-1].find('1')
ans = 0
k = 1
while True:
  n //=2
  ans += k
  k *= 2
  if n == 1:
    break

print(ans+k)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import sys
input=sys.stdin.readline

h=int(input())
cnt1=0
cnt2=1

while True:
    h=h//2
    cnt2*=2
    cnt1 += cnt2//2
    if h==1:
        break

print(cnt1+cnt2)

Submission status: Time Limit Exceeded

Solution code:
h=int(input())
X=0
a=1
if h<4:
  while True:
    X=X+1*a
    a=a*2
    h=h//2
    if(h==1):
      break
    X=X+a    
    print(X)
else:
  for i in range(h):
    if h//2**i<=0:
      a=i
      break
print(2**a-1)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
i = 1
result = 0

while True:
    H //= 2
    result += 2**i
    i += 1
    if H == 1:
        break
 
print(result+1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

# i = format(n, 'b')[::-1].find('1')
i = 0
ans = 0
while True:
  n //=2
  ans += 2**i
  i += 1
  if n == 1:
    break

print(ans+2**i)

Submission status: Time Limit Exceeded

Solution code:
ipt = int(input())
monster=[ipt]

count=0
while len(monster)>0:
	hp=monster[0]
	count+=1
	monster.pop(0)
	if hp>1:
		monster.append(hp//2)
		monster.append(hp//2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    H = int(input())
    n = 1
    ans = 0
    a = 1
    while a == 1:
        H = H // 2
        n += 1
        if H == 1:
            break
    print(2 ** n - 1)
main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

# i = format(n, 'b')[::-1].find('1')
i = 0
while True:
  n //=2
  i += 1
  if n == 1:
    break


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

cnt = H
B = [H]
for i in range(1000000000):
    cnt = cnt//2
    B.append(cnt)
    if cnt == 1:
        break

C =[1]
for i in range(1,100):
    C.append(C[i-1]*2)

ans= 0
for i in range(len(B)):
    ans +=C[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

cnt = H
B = [H]
for i in range(1000000000):
    cnt = cnt//2
    B.append(cnt)
    if cnt == 1:
        break

C =[1]
for i in range(1,1000):
    C.append(C[i-1]*2)

ans= 0
for i in range(len(B)):
    ans +=C[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

cnt = H
B = [H]
for i in range(1000000000):
    cnt = cnt//2
    B.append(cnt)
    if cnt == 1:
        break

C =[1]
for i in range(1,10000):
    C.append(C[i-1]*2)

ans= 0
for i in range(len(B)):
    ans +=C[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
i=0
while True:
  n = n//2
  i += 1
  if n == 1:
    break

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    H = int(input())
    n = 1
    ans = 0
    a = 1
    while a == 1:
        H = H // 2
        n += 1
        if H == 1:
            ans = 2 ** n - 1
            break
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
h=int(input())
X=0
a=1
if h>3: 
  h=h//2
  while True:
    X=X+1*a
    a=a*2
    h=h//2
    if(h==1):
      break
  X=X*2
  a=a*2
  X=X+a+1
  print(X)

else:
  while True:
    X=X+1*a
    a=a*2
    h=h//2
    if(h==1):
      break
  X=X+a    
  print(X)

Submission status: Time Limit Exceeded

Solution code:
import math

monster_hp_list = []
monster_hp_list.append(int(input()))

count = 0

def floor_divide(hp_list):    
    return math.floor(hp_list/2)

while(monster_hp_list[0] != 1): 
    count += len(monster_hp_list)
    monster_hp_list = list(map(floor_divide,monster_hp_list))*2
    
    

count += len(monster_hp_list)
print(count)

Submission status: Time Limit Exceeded

Solution code:
H = 1000000000000
key = H
i = 0
mon_cnt = [1]
while key > 1:
    key = round(key / 2)
    key_box = []
    i += 1
    for _ in range(2 ** i):
        mon_cnt.append(key)
print(len(mon_cnt))

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
M = []
M.append(H)

A = 0

while len(M) > 0:
  if M[0] == 1:
    M.remove(M[0])
    A += 1
  else:
    M.append(int(M[0]/2))
    M[0] = int(M[0] / 2)
    A += 1

print(A)

Submission status: Time Limit Exceeded

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

if H==1:
    print(1)
else:
    d = deque([H])
    # d=[H]
    while(len(d)>0):
        monster = deque.pop(d)
        count+=1
        if monster>1:
            tmp = monster//2
            if tmp==1:
                count+=2
            else:
                d.extend([tmp, tmp])
    print(count)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
if H == 1:
    cnt = 1
else:
    J = list()
    J.append(H)
    cnt = 0
    while len(J) > 0:
        if J[0] == 1:
            del J[0]
            cnt += 1
        else:    
            J.append(J[0]//2)
            J.append(J[0]//2)
            del J[0]
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    H = int(input())
    n = 0
    ans = 0
    a = 1
    while a == 1:
        H = H // 2
        ans = ans + pow(2, n)
        n += 1
        if H == 1:
            ans = ans + pow(2, n)
            break
    print(ans)
main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
h = int(input())
h_list =[]
h_list.append(h)
count = 0
while True:
    if len(h_list) > 1 and h_list[0] ==1:
        count += 1
        h_list.pop(0)
    elif h_list[0] > 1 :
        count += 1
        h_list.append(math.floor(h_list[0]/2))
        h_list.append(math.floor(h_list[0]/2))
        h_list.pop(0)
    elif len(h_list) == 1 and h_list[0] == 1 :
        count +=1
        print(count)
        break

Submission status: Time Limit Exceeded

Solution code:

def a(H):
    global ans
    if H <= 1:
        ans = ans + 1
    else:
        ans = ans + 1
        a(H // 2)
        a(H//2)


H = int(input())
ans = 0
a(H)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
i = 1
result = 0

while True:
    H //= 2
    result += 2**i
    i += 1
    if H == 1:
        break

print(result+1)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
n = 0
import math
while True:
    h = math.floor(h/2)
    n += 1
    if h == 1:
        break
        
print(2**(n+1)-1)

Submission status: Time Limit Exceeded

Solution code:
def attack():
    if H[0] == 1:
        H.pop(0)
    else:
        H.append(H.pop(0)//2)
        H.append(H[-1])

H = [int(input())]
count = 0
while (H != []):
    attack()
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))

#ans_L = [0] * (10**12 + 1)

i = 0
ans_L = [1]
while True:
    h = h//2
    i += 1
    ans_L.append(2**i)
    if h == 1:
        break

print(sum(ans_L))

Submission status: Time Limit Exceeded

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

H = int(input())

ans = 1
prev = 1
while True:
    H //= 2
    prev *= 2
    ans += prev
    if H == 1:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def attackCounter(array, cnt):
    if len(array) == sum(array):
        cnt += len(array)
        return cnt
    else :
        cnt += len(array)
        array = [i // 2 for i in array] * 2
        return attackCounter(array, cnt)

H = int(input())
cnt = attackCounter([H], 0)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
H=int(input())
flag=False
c=0
ans=1
while flag==False:
#for i in range(4):
    H=H//2
    c+=1
    ans+=2**c
    if H==1:
        #break
        flag=True
#print(c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
li = []
li.append(h)
c=1
while(h >  1):
    h= int(h/2)
    for i in range(2**c):
        li.append(h)
    c += 1

print(len(li))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while True:
    H //= 2
    i += 1
    if H == 1:
        break

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
H=int(input())
flag=False
c=0
while flag==False:
#for i in range(4):
    H=H//2
    c+=1
    if H==1:
        #break
        flag=True
#print(c)
ans=0
for j in range(c+1):
    ans+=2**j
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
H = []
H.append(h)
tot = 0
i = 0

while len(H) > 0:
    i = len(H) - 1
    if H[i] > 1:
        tot = tot + 1
        H.append(int(H[i]/2))
        H[i] = int(H[i]/2)
    else:
        tot = tot + 1
        H.pop(i)

        
print(tot)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())

for i in range(10**12):
  h = h // 2
  if h == 1:
    break
    
#print(i+1)
ans = 0
for j in range(i+2):
  ans += 2**j
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
li = []
li.append(h)
c=1
while(h != 1):
    if(h>1):
        h= int(h/2)
        for i in range(2**c):   #計算量がクソ多くなる
            li.append(h)
    c += 1

#print(li)
print(len(li))

Submission status: Time Limit Exceeded

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

while True:
    H //= 2
    i += 1
    if H == 1:
        break

suretu = [None] * (i + 1)

for i in range(i+1):
    suretu[i] = 2**i

result = sum(suretu)
print(result)

Submission status: Time Limit Exceeded

Solution code:
h=int(input())
count=1
ans=1
v=h
while True:
    temp=v//2
    #count=count*2
    #ans+=count
    if temp==1:
        #count=count*2
        ans+=1
        #ans+=count
        break
    v=temp
    #count=count*2
    #ans+=count
    ans+=1
    
print(int((1-2**ans)/(1-2)))

Submission status: Time Limit Exceeded

Solution code:
i=int(input())
nest=1
a=0
p=i
while True:
  nest+=1
  p=p//2
  if p==1:
    break
a=(2**nest)-1
print(a)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())

monsters = []
atack_num = 0

monsters.append(h)

while 1:
  for i in range(len(monsters)):
    if monsters[i] == 1:
      atack_num += 1
      monsters[i] = 0
    elif monsters[i] > 1:
      atack_num += 1
      monsters.append(monsters[i]/2)
      monsters.append(monsters[i]/2)
      del monsters[i]
  if sum(monsters) == 0:
    break

print(atack_num)

Submission status: Time Limit Exceeded

Solution code:
E = []
E.append(int(input()))
count = 0

while len(E) != 0:
    if E[0] // 2 == 0:
        count += 1
        E.pop(0)
    else:
        E.append(E[0] // 2)
        E.append(E[0] // 2)
        E.pop(0)
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
i=int(input())
nest=1
a=0
p=i
while True:
  nest+=1
  p=p//2
  if p==1:
    break
for k in range(nest):
  a+=2**k
print(a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

n = int(input())
print(karac(n))

Submission status: Time Limit Exceeded

Solution code:
h=int(input())
count=1
ans=1
v=h
while True:
    temp=int(v//2)
    #count=count*2
    #ans+=count
    if temp==1:
        count=count*2
        ans+=count
        break
    v=temp
    count=count*2
    ans+=count
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def attack(x):
    if x <= 1:
        return 1
    else:
        ans = 0
        ans += attack(int(x / 2))
        ans += attack(int(x / 2))
        ans += 1
        return ans

h = int(input().rstrip())
at = attack(h)
print(at)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

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

total = 0
for n in range(count + 1):
    total += 2 ** n

print(total)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

lst = [H]
cnt = 0
while len(lst) > 0:
    cnt += 1
    mon = lst.pop()
    if mon == 1:
        continue
    else:
        new_mon = (mon // 2)
        lst.append(new_mon)
        lst.append(new_mon)
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
ans = 1
ls = []
i = 1
while True:
    #print(ans)
    h //= 2
    ans += 2*i
    i += 1+(i-1)
    if h == 1:
        break
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
cnt=1
x=1
while True:
    H=H//2
    if H==1:
        cnt*=2
        x+=cnt
        print(x)
        exit()
    cnt*=2
    x+=cnt

Submission status: Time Limit Exceeded

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

while(1):
    if h >= 2**(i+1) and h < 2**(i+2):
        print(2**(i+2)-1)
        exit(0)

    i = i + 1

Submission status: Time Limit Exceeded

Solution code:
def main():
    h = int(input())
    cnt = 0
    ans = 0
    tmp = 1
    while True:
        h //=2

        cnt += tmp
        tmp *= 2
        if h==1:
            break

    print(cnt+tmp)
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

time = 0
now = H

while True:
    now = now//2
    time += 1
    if now == 1:
        break
pow2list = [2**i for i in range(50)]
ans = sum(pow2list[0:time+1])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

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

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

print(L)

Submission status: Time Limit Exceeded

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

print(2 ** n - 1)

Submission status: Time Limit Exceeded

Solution code:
import math

H = int(input())
#H = list(map(int,input().split()))
#H = sorted(H,reverse=True)

mon_num = 1
attack_num = 0
for k in range(1000000000000):
    
    attack_num += mon_num
    
    H = math.floor(H/2)
    mon_num = mon_num*2
    
    
    if H == 1:
        attack_num += mon_num
        break
print(attack_num)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

count = 0
number = 1
while True:
    H = H // 2
    number *= 2
    if H == 1:
        count += number + 1
        break
    else:
        count += number

print(count)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

lst = [0]
for i in range(1, 10**12):
    if i == 1:
        lst.append(1)
    else:
        tmp = lst[i//2]*2 + 1
        lst.append( tmp )
    
    if i == H:
        print(lst[i])
        exit()

Submission status: Time Limit Exceeded

Solution code:
h = int(input())

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
l = [int(input())]

count = 0
while True:
  if l == []:
    break
  if l[-1] == 1:
    l.pop(-1)
  else:
    temp = l[-1]//2
    l.pop(-1)
    l.append(temp)
    l.append(temp)
  count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Accepted

Solution code:
H = int(input())
attackcnt = 0
monstercnt = 1
def monster(h, m, a):
    if h == 1:
        return 0,0,a+m
    else:
        return monster(int((h/2)),2*m,a+m)
a, b, c = monster(H,monstercnt,attackcnt)
print(c)

Submission status: Accepted

Solution code:
H = int(input())
now = 1
for i in range(1,100):
  if now <= H <= now*2-1:
    print(2**i-1)
    break
  else:
    now *= 2

Submission status: Accepted

Solution code:
n = int(input())
s = 1
t = 0
while s <= n:
  s = s*2
  t += 1
print(2**t-1)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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


def solve(H: int):
    if H == 1:
        print(1)
        return
    i = 2
    c = 3
    while True:
        i *= 2
        if i > H:
            print(c)
            break
        c = c * 2 + 1


    return


# Generated by 1.1.7.1 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:
H = int(input())
ii = 1
while H != 1:
    ii += 1
    H = H//2
print(2**ii-1)

Submission status: Accepted

Solution code:
def myfunc(N):
	if(N  <= 1):
		return 1
	return 2 * myfunc(int(N/2)) + 1

if __name__ == "__main__":
	N = int(input())
	print(myfunc(N))

Submission status: Accepted

Solution code:
h = int(input())
count = 0
for i in range(40):
    count += 2**i
    if h >= 2 ** i and h < 2 ** (i+1):
        break
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
H = int(input())
l = math.log(H,2)
ll = math.floor(l)+1
ans = 2 ** ll -1
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
h = int(input())

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

print(cal(h))

Submission status: Accepted

Solution code:
h = int(input())
sumn = 0
i,k = 0,1
while k <= h:
    sumn+=k
    i+=1
    k = 2**i
    
print(sumn)

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

def main():
    N = 0
    H = int(input())
    ans = 0

    while (True):
        H //= 2
        if H == 0:
            break
        N += 1

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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

h = int(input())
atk = 0
enemy = 1

while True:
    if h > 1:
        h = math.floor(int(h/2))
        atk += enemy
        enemy *= 2
    elif h == 1:
        atk += enemy
        break

print(atk)

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

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

from  collections import defaultdict
from collections import Counter
import bisect
from functools import reduce

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

H = int(input())
ans = 0
num = 0

while True:
    ans += 2**num   
    if H == 1:
        print(ans)
        break
    else:
        H = math.floor(H/2)
        num += 1

Submission status: Accepted

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

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

print(2**count - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import *
H = int(input())
print(2**(int(log2(H))+1)-1)

Submission status: Accepted

Solution code:
import math

def main():
    H = {int(input()): 1}
    ans = 0
    while True:
        new_H = {}
        for h, freq in H.items():
            ans += freq
            if h > 1:
                new_H[h // 2] = 2 * freq
        if len(new_H) == 0:
            break
        else:
            H = new_H
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())
def fh(x):
    if x==1:
        return 1
    else:
        return 2*fh(x//2)+1
ans=fh(h)
print(ans)

Submission status: Accepted

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

while hp:
    hp //= 2
    n += 1

print(2**n-1)

Submission status: Accepted

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

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

def main():
    mod=10**9+7
    H=I()
    ans=0
    
    def f(x):
        if x==0:
            return 0
        return f(x//2)*2 +1
    
    print(f(H))
        

main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
H = int(input())
h = H
count = 1
total_count = count
while h > 1:
  count *= 2
  total_count += count
  h //= 2
print(total_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    enemy_hp = int(input())
    enemy_count=1
    attack_count=1

    if enemy_hp==1:
        print(1)
        exit()
    else:
        while enemy_hp >1:
            enemy_hp = int(enemy_hp/2)
            enemy_count*=2
            attack_count+=enemy_count
            
    print(attack_count)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
# 26
H = int(input())

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

ans = getAns(H)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

cnt = 0
ans = 0

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

print(ans+1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
H=int(input())
s=1 #sはモンスターの数
t=0
while H>1:
    H=H//2
    s=s*2
    t=t+1

list=[]
u=1
while u<=t:
    list.append(u)
    u=u+1

z=0
for i in list:
    z=z+2**(i-1)

print(str(z+s))

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0
res = 0

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

print(res+1)

Submission status: Accepted

Solution code:
import sys
import copy
import math
import itertools

H = int(input())
cnt = 0
for i in range(int(math.log2(H))+1):
    cnt+=2**i
print(cnt)

Submission status: Accepted

Solution code:
H = int(input())

i = 0
while True:
  if H < 2 ** i:
    n = i
    break
  i += 1

print(2**n -1)

Submission status: Accepted

Solution code:
H = int(input())
 
# 体力がHのモンスター1体に勝つために必要な攻撃回数をf(H)とする
# すると、f(H)は以下の漸化式に従って求まる
# f(H)=2*f(floor(H/2)+1) (H>1)
# f(H)=1 (H=1)

# 漸化式の実装はAtCoderで珍しい。パターンとして覚えよ！
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:
H = int(input())
 
# 体力がHのモンスター1体に勝つために必要な攻撃回数をf(H)とする
# すると、f(H)は以下の漸化式に従って求まる
# f(H)=2*f(floor(H/2)+1) (H>1)
# f(H)=1 (H=1)

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:
H = int(input())
 
# 体力がHのモンスター1体に勝つために必要な攻撃回数をf(H)とする
# すると、f(H)は以下の漸化式に従って求まる
# f(H)=2*f(floor(H/2)+1) (H>1)
# f(H)=1 (H=1)
 
def attack_num(x):
  if x == 1: return 1
  else: return 2*attack_num(x // 2) + 1
  
print(attack_num(H))