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 nextPow(x):
    xx = 1
    while xx * 2 <= x:
        xx *= 2
    return xx

# 3//2 == 1
# 偶数と奇数は同じ答え
# 2 => 2 + 1
# 4 => 6 + 1
# 6 => 6 + 1
# 8 => 20 + 1
# 10 => 20 + 1
# 10 => 5,5, 7+7 + 3 + 3 1

import math

H = int(input())
result = 1

# ２の乗数分の配列が出来るはず
# 2の乗数で 敵の数が増える
# 2,4,8,16....
# 乗数が上がるごとに
# 2の乗数が一個増えると、その乗数 -1 増える

first = 1
if H == 1:
    print(1)
    exit(0)
elif H == 2:
    print(first + 1 + 1)
    exit(0)
elif H == 3:
    print(first + 1 + 1)
    exit(0)

result = 1
np = nextPow(H)
result += (np - 1) * 2

print(result)

# first = 1
# if H == 1:
#     print(1)
# elif H == 2:
#     print(first + 1 + 1)
# elif H == 3:
#     print(first + 1 + 1)
# elif H == 4:
#     print(first + 3 + 3)
# elif H == 5:
#     print(first + 3 + 3)
# elif H == 6:
#     print(first + 3 + 3)
# elif H == 7:
#     print(first + 3 + 3)
# elif H == 8:
#     print(first + 7 + 7)
# elif H == 9:
#     print(first + 7 + 7)
# elif H == 10:
#     print(first + 7 + 7)
# elif H == 11:
#     print(first + 7 + 7)
# elif H == 12:
#     print(first + 7 + 7)
# elif H == 13:
#     print(first + 7 + 7)
# elif H == 14:
#     print(first + 7 + 7)
# elif H == 15:
#     print(first + 7 + 7)
# elif H == 16:
#     print(first + 15 + 15)

Submission status: Accepted

Solution code:
H=[int(input())]
m=0
while len(H)!=0:
    for i in H:
        if i>1:
            H.append(int(i/2))
            H.remove(i)
            m=(m+1)*2
        else:
            H.remove(i)
            m+=1
print(m)

Submission status: Accepted

Solution code:
import sys

use_clipboard=True
bbn=1000000007
	
#+++++

class dd:
	def __init__(self, a_h):
		self.h=a_h

		
def main():
	h=int(input())
	ret = 0
	ec=1
	while h >= 1:
		ret += ec
		ec *= 2
		h = h // 2 
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
class input_clipboard:
	def __init__(self,s):
		self.input_l=s.splitlines()
		self.ii=0
		
	def input(self):
		ret = self.input_l[self.ii]
		self.ii+=1
		return ret

if __name__ == "__main__":
	if sys.platform =='ios':
		if use_clipboard:
			import clipboard
			input_text=clipboard.get()
			ic=input_clipboard(input_text)
			input = lambda : ic.input()
		else:
			sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

result = 0
i = 1
while H > 0:
    H = H // 2
    result = result + i
    i *= 2

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

if h > 1:
  while h >= 1:
    h = h / 2 
    count = count + 1
  for i in range(0, count):
    attack = attack + (2**i)
  print(attack)
else:
  print(1)

Submission status: Accepted

Solution code:
import numpy as np
import math 

h = int(input())


temp = math.floor(np.log2(h))
temp_sum = sum([2**i for i in range(0, temp)])

print(temp_sum+2**temp)

Submission status: Accepted

Solution code:
def main():
    H =int(input())
    bit_list = list(bin(H))
    del bit_list[:2]
    bit_in = [s.replace('0', '1') for s in bit_list]
    mojiretu = ' '
    for x in bit_in:
        mojiretu += x
    print(int(mojiretu, 2))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

H = int(input())

ans = 1

tmp = H
bef = 1


while tmp > 1:
  tmp = tmp // 2
  
  if tmp >= 1:
    bef *= 2
    ans += bef

print(ans)

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:

def main():
    from sys import stdin, setrecursionlimit
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    n = int(stdin.readline()[:-1])   
    #r = stdin.readline()[:-1]
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    #n = int(r)
    #a = r.split()
    #a,b,c = r.split()
    #a = list(map(int, r.split()))
    #h,n = map(int, r.split())
    #r = stdin.readline()[:-1]
    #a = list(map(int, r.split()))
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]
    #a = [list(map(int, r.split())) for i in range(n)]
    #res = 0

    import math
    cnt = 0
    while n > 0:
        n = math.floor(n/2)
        cnt += 1
    print(2**(cnt)-1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = input()
n = int(n)
count = 0
attack = 0

if n > 1:
  while n >= 1:
    n = n / 2 
    count = count + 1
  for i in range(0, count):
    attack = attack + (2**i)
  print(attack)
else:
  print("1")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())
def cut(a):
	if a==1:
		return 1
	elif a%2==1:
		return 2*cut((a-1)//2)+1
	elif a%2==0:
		return 2*cut(a//2)+1
print(cut(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math

H = input()
H_bar=int(H)
counter=0
bunki=0

while H_bar!=1:
 H_bar=math.floor(H_bar/2)
 bunki=bunki+2**counter
 counter=counter+1
  
Sum=bunki+2**counter
print(Sum)

Submission status: Accepted

Solution code:
a = int(input())
attack_num = 0
num_list = []
count = 1

def attack(hp):
  global attack_num,num_list,count
  
  attack_num = attack_num + count
  count = count *2
  if hp <= 1:
    num_list.append(attack_num)
  elif hp % 2 == 0:
    attack(hp/2)
  elif hp % 2 == 1:
    attack((hp-1)/2)
    
    
attack(a)
print(num_list[-1])

Submission status: Accepted

Solution code:
import math

H = int(input())
ans = int(math.log(H, 2)) + 1
a = ans - 1
r = 0


for _ in range(ans - 1):
    ans += a * (2 ** r)
    r += 1
    a -= 1

print(ans)

Submission status: Accepted

Solution code:
import math
h = int(input())
 
s=0 
x=0
b = int(math.log(h, 2) + 1)
for i in range(b):
  if h is not 0:
    h = h/2
    s+=2**i
  else:
    continue
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n=int(input())
n2=int(math.log(n,2))

print(2*(2**n2)-1)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
N = bin(N)
x = len(str(N)) - 2

print(2 ** x - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

H = int(input())
counter = 1

if H != 1:
    while True:
        H = math.floor(H / 2)
        if H > 1:
            counter += 1
        elif H == 1:
            break
    print(2**(counter + 1 ) - 1)
else:
    print(1)

Submission status: Accepted

Solution code:
H = int(input())

n = 0

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

ans = (2**n-1) + (2**n) #(割り算の回数)＋(１への攻撃回数）

print(ans)

Submission status: Accepted

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

phase = 1
cnt = 1
while True:
    if H == 1:
        break
    H = math.floor(H/2)
    cnt += 2 ** phase
    phase += 1
print(cnt)

Submission status: Accepted

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


def solve(H: int):
    count = 0
    i = 0
    while H >= 1:
        H = H // 2
        count = count + 2 ** i
        i += 1
    print(count)

    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:
num = int(input())
num2 = bin(num)
keta = len(num2)-2
if num == 1:
  print(1)
else:
  print(2 ** keta -1)

Submission status: Accepted

Solution code:
import math
H = int(input())
i = 1
if H == 1:
    print(1)
else:
    while H > 1:
        i = i + 1
        H = math.floor(H / 2)
    print(2 ** i - 1)

Submission status: Accepted

Solution code:
import math
H = int(input())
height = 1
div = H
while div > 1:
  div = math.floor(div / 2)
  height += 1
count = 2 ** height - 1

print(count)

Submission status: Accepted

Solution code:
h = int(input())
cnt=0
while h>1:
  h=h//2
  #print(h)
  cnt+=1
  
n=cnt
"""
#print(cnt)
sn = (n/2)* (4+(n-1)*2)
sn+=1
#print(int(sn))
"""
r = 2
sn = ( 2*(r**n -1) )/(r-1)
  
print(int(sn+1))

Submission status: Accepted

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

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

print(2**count - 1)

Submission status: Accepted

Solution code:
def a(H):
    global ans
    global dic
    if H // 2 in dic:
        add = 2 * ans + 1
        ans = add
        dic[H] = add
    else:
        a(H//2)
        a(H//2)

H = int(input())
dic = {}
dic[1] = 1
ans = 1
if H != 1:
    a(H)
print(ans)

Submission status: Accepted

Solution code:
h=int(input())
c=0
if h==1:
    print("1")
else:
    while h!=1:
        h=h//2
        c=c+1
    k=pow(2,c+1)-1;
    print(k)

Submission status: Accepted

Solution code:
import math
h = int(input())
i = 0
c = 0
while h != 0:
    c += 2**i
    if h > 1:
        h = math.floor(h/2)
    else:
        h = 0
    i += 1
print(c)

Submission status: Accepted

Solution code:
import math

h = int(input())
sep_cnt = math.floor(math.log2(h))
ans = 2 ** (sep_cnt + 1) - 1
print(ans)

Submission status: Accepted

Solution code:
H = int(input())
n_layer = 1
while H > 1:
    H //= 2
    n_layer += 1
print(sum([2**i for i in range(n_layer)]))

Submission status: Accepted

Solution code:
# coding: utf-8

H = int(input())
count = 1
ans = 1
while H >= 2:
    ans += 2**count
    H = H >> 1
    count += 1
print(ans)

Submission status: Accepted

Solution code:
import math
import numpy as np
H=int(input())

n = int(np.log2(H))
ans = 2**(n+1)-1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
i = 1
while ( i * 2 <= n):
    i *= 2
print(i*2-1)

Submission status: Accepted

Solution code:
# count = 0
# summ = 0
def aaa(h, summ, count):
    summ += 2 ** count
    count += 1
    
    if h == 1:
        print(summ)
        return summ
    else:
        aaa(h // 2, summ, count)

H = int(input())
summ = aaa(H, 0, 0)
# print(summ)

Submission status: Accepted

Solution code:
import math
H = int(input())
count = 0
enemy = 1
enemyH = H
while enemy > 0:
  if enemyH == 1:
    count += enemy
    enemy =0
  else :
    X = (enemyH/2)
    x = math.floor(X)
    enemyH =x
    count += enemy
    enemy =enemy*2
print(count)

Submission status: Accepted

Solution code:
monster_num = int(input())
times = 0
while(monster_num >= 1):
  monster_num = int(monster_num / 2)
  times += 1
ans_times = 0
for n in range(times):
  ans_times += 2 ** n
print(ans_times)

Submission status: Accepted

Solution code:
import math
H=int(input())
log2_H=math.log2(H)
log2_H_floor=math.floor(log2_H)
N=log2_H_floor+1
print(2**N-1)

Submission status: Accepted

Solution code:
A = int(input())
ans_list = []
i = A
while i != 1:
    i = i//2
    ans_list.append(i)
B = len(ans_list)
a = 3
for i in range(1,B):
    a = a * 2 + 1
if A == 1:
    print(1)
else:
    print(a)

Submission status: Accepted

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

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

flag = True
n = 1
depth_num = 2

while flag:
    if 2 ** n - 1  < h:
        n += 1
    else:
        flag = False
        depth_num = n

result_num = 2 ** depth_num - 1
print(result_num)

Submission status: Accepted

Solution code:
h = int(input())

result = 0
i = 1
while h > 0:
    h = h // 2
    result = result + i
    i *= 2

print(result)

Submission status: Accepted

Solution code:
h = int(input())

count = 0 
n = 0

while h > 1:
    h = int(h/2)
    n += 1
    count += pow(2, n-1)

count += pow(2, n)
print(count)

Submission status: Accepted

Solution code:
import math

log = int(math.log2(int(input())))

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

print(num)

Submission status: Accepted

Solution code:
H = int(input())

i = 0
A = 0

while H >= 2**i:
  i += 1
  
for j in range(i):
  A += 2**j
print(A)

Submission status: Accepted

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

ans = 1
teki = 1

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

print(ans)

Submission status: Accepted

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

def attack(h):
    global count
    count += 1
    if h ==1:
        return 0
    if h > 1:
        attack(h // 2)

attack(H)
if H == 1:
    print(1)
else:
    # 完全二分木の接点数
    print(2 ** (count) - 1)

Submission status: Accepted

Solution code:
h = int(input())
#2n-1,2**2
for i in range(10**12):
    if 2**i > h:
        check = i-1
        break
print(2*(2**check)-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

i = 0
j = 1
while H != 1:
  H = H//2
  i += 2**j
  j += 1

print(i + 1)

Submission status: Accepted

Solution code:
h = int(input())

num = 0
while(1):
    num += 1
    h = h // 2
    if h < 1:
        break

print(2 ** num - 1)

Submission status: Accepted

Solution code:
h = int(input())
# li = []
# li.append(h)
n = x = 0
b = True
while b:
  if h != 1:
    h = h // 2
    n += 1
  else:
    b = False

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
count = 1

def number(h,count):
    if h<= 1:
        return count
    else:
        return number(h//2,count+1)
h = int(input())
#print(keisan(h,count))
key = number(h//2,count)
ans = 0
if h == 1:
    print(1)
else:
    for i in range(1,key+1):
        ans += 2**i
    print(ans+1)

Submission status: Accepted

Solution code:
h = int(input())
mem = [0] * 1000
cnt = 0

def atk(k):
    if k == 1:
        return 1
    else:
        j = int(k // 2)
        l = 0
        while k / ( 2 ** l) >1:
            l += 1

        if mem[l] == 0:
            mem[l] = atk(j) * 2 + 1
            return mem[l]
        else:        
            return mem[l]
if h > 1:
    atk(h)
    mem.sort(reverse = True)
    print(mem[0])
else:
    print(1)

Submission status: Accepted

Solution code:


H=int(input())

#print(H)

COUNT = 0
for i in range(10000000000):
    temp = pow(2,i)
    if temp == H:
        COUNT = i
        break
    elif temp > H:
        COUNT = i-1
        break

#print(COUNT)

SUM = 0
for j in range(COUNT+1):
    SUM += pow(2,j)

print(SUM)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
if H == 1:
  print(1)
  exit()
n, cnt = 1, 1
# while n < H:
while cnt < H:
  n *= 2
  cnt += n
  # print(cnt)
print(cnt)

Submission status: Accepted

Solution code:
H = int(input())

b = len(format(H, 'b'))

sum = 0
for i in range(0, b):
    sum += 2 ** i

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())

k=0
p=0
while h!=1:
    k+=2**p
    h=h//2
    p+=1
print(k+2**p)

Submission status: Accepted

Solution code:
H = int(input())
s2 = 0
if H == 1:
    print(1)
else:
    while H >= 2**s2:
        s2 +=1
    s2 -= 1
    s3 = 1
    cnt = 3
    while s3 < s2:
        cnt = 1 + cnt *2
        s3 += 1
    print(cnt)

Submission status: Accepted

Solution code:
m=int(input())
i = 0
while m > 0:
  m = m//2
  i += 1
li=list(range(i))
la=[2**x for x in li]
print(sum(la))

Submission status: Accepted

Solution code:
import math

H = int(input())
i = 1
while ( i * 2 <= H):
    i *= 2

k = int(math.log(i, 2))

def f(n):
    return 2 ** n

def sigma(func, frm, to):
    result = 0;
    for i in range(frm, to+1):
        result += func(i) 
    print(result)
    
sigma(f, 0, k)

Submission status: Accepted

Solution code:
import math
import numpy as np
N = int(input())

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

print(answer)

Submission status: Accepted

Solution code:
H = int(input())

memo_count = {}
def searchCount(h):
    if h==1: # 脱出条件
        return 1
    elif h in memo_count:
        return memo_count[h]
    else:
        h_half = int(h / 2)
        memo_count[h] = 1 + 2*searchCount(h_half)
        return memo_count[h]

print(searchCount(H))

Submission status: Accepted

Solution code:
H=int(input())
temp=H
answer=0

for i in range(100):
    if  abs(H-2**i)<temp:
        temp=abs(H-2**i)
        answer=i
        #print("before")
        #print(i)
        
    else:
        fuge=0
        #print("fuge")
        #print(i)
        
if H<(2**answer):
    #つまりHは2^answer以内にいる。
    print(2**answer-1)
else:
    #つまりHは2^answer+1以内にいる。
    print(2**(answer+1)-1)

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

H = int(input())
i = 1
j = [1]

while H > 1:
    H = math.floor(H/2)
    i = i * 2
    j.append(i)

print(sum(j))

Submission status: Accepted

Solution code:
from functools import lru_cache
h = int(input())
count = 0

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

@lru_cache(maxsize=100000)
def f(n):
    if n < 1:
        return 1
    else:
        return f(n - 1)*2 + 1

print(f(count))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
LogT={1:1}
def  div2(X):
    if X in LogT:
        return LogT[X]
    else:
        v = 1+div2(math.floor(X/2))*2
        LogT[X]=v
        return v

if __name__=='__main__':
    H=int(input())
    print (div2(H))

Submission status: Accepted

Solution code:
h = int(input())
if h == 0:
  print(0)
  quit()
i = 0
while True:
  if h < 2**i:
    print(2**i - 1)
    quit()
  else:
    i += 1
# I love kemofure

Submission status: Accepted

Solution code:
h = int(input())

count = 0
while count >= 0 :
  count += 1
  if h != 1 :
    h = h // 2
    count = count*2
  else :
    print(count)
    break

Submission status: Accepted

Solution code:
h=int(input())

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

Submission status: Accepted

Solution code:
H=int(input())
#0bを除く
N=len(bin(H))-2

count=0
if sum(list(map(int, bin(16)[3:])))==0:
  for i in range(N):
    count+=2**i
else:
  N=N+1
  for i in range(N):
    count+=2**i
    
print(count)

Submission status: Accepted

Solution code:
import math

h = int(input())
count = 1

while h != 1:
  h = math.floor(h/2)
  count += 1

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

Submission status: Accepted

Solution code:
H = int(input())

# monster HP is X
# X==1 >> X=0
# X>1  other 2 monster appear. These 2 mosters have [X/2] HP.
# No.i monster vitalitiy is Hi
# two actions
# attack : reduce 1 vitaility
# special: make vitality 0. Fenek can use K times of specials.
# print(type(2*10**14))

# from collections import deque
#
# print(f"H={H}")
#
# monsters = deque()
# monsters.append(H)
# attack = 0
#
# while monsters:
# # for _ in range(3):
#     hp = monsters.popleft()
#     # print(f"attack to monster(HP={hp})")
#     if hp != 1:
#         # print(f"new 2 monsters(HP={hp//2}) appears!")
#         hp_hp = hp//2
#         monsters.extend([hp_hp, hp_hp])
#         # print(monsters)
#     attack += 1

i = 1
while H > 1:
    H //= 2
    i += 1
# print(attack)
print(2**i - 1)

Submission status: Accepted

Solution code:
N = int(input())
L = [1]
count = 1
while N > 1:
    N = int(N/2)
    count *=2
    L.append(count)
print(sum(L))

Submission status: Accepted

Solution code:
H = int(input())

count = 0
damage = 1
sum_damage = 1

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

for i in range(1, count):
    damage = damage * 2
    sum_damage += damage

print(int(sum_damage))

Submission status: Accepted

Solution code:
h=int(input())

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

Submission status: Accepted

Solution code:
H = int(input())
bin_H = format(H,'b')
n = int(len(bin_H))

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

Submission status: Accepted

Solution code:
h = int(input())
for i in range(1000):
    if h == 0:
        a = 2 ** (i)-  1
        print(a)
        break
    h = h // 2

Submission status: Accepted

Solution code:
import numpy as np
import math


N = int(input())

res = 1

end = N // 2

#if N == 1:
#    print(res)  # 1
for i in range(math.floor(np.log2(N))):
    res = res * 2 + 1

print(res)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

h = int(read())

q = [h]
now = h

while now > 1:
  now = math.floor(now / 2)
  q.append(now)

total = 1
for i in range(1, len(q)):
  total += 2 ** i

print(total)

Submission status: Accepted

Solution code:
import math
H = int(input())
if H == 1:
    print(H)
else:
    print(int(math.pow(2,int(math.log2(H))+1)-1))

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
#abc153 a
#153 c
def n_jou(n):
    cnt=0
    while n>1:
        n=int(n/2)
        cnt+=1
    return cnt

n=int(input())
k=n_jou(n)
ans=0
for i in range(k+1):
    ans+=2**i
print(ans)

Submission status: Accepted

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

while H > 1:
    if H%2 == 0:
        H = H/2
        ans += 1
    else:
        H = (H-1)/2
        ans += 1
N = 2**ans
def fight(k):
    if k == 1:
        return 1
    else:
        return 2*fight(k/2)+1
    
        
print(fight(N))

Submission status: Accepted

Solution code:
h = int(input())

import math

ans = 1
p_ans = 1

logh = int(math.log2(h))
for i in range(logh):
  ans += p_ans * 2
  p_ans = p_ans * 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

print(dfs(h))

Submission status: Accepted

Solution code:
import math
a = list(map(int,input().split()))
b = int(math.log(a[0], 2))
c = 2 ** (b+1) -1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())

a=0
i=1
while H >0:
    a=a+i
    i=i*2
    H=H//2
print(a)

Submission status: Accepted

Solution code:
H = int(input())

counter = 0
sub = 1

while H > 0:
    H = int(H/2)
    counter += sub
    sub *= 2

print(counter)

Submission status: Accepted

Solution code:
import math
H = int(input())
def atack(X):
  if (X <= 1):
    return 1
  else:
    return 1 + atack(math.floor(X/2))*2
print(atack(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

# H モンスターの体力
h = int(input())

bin_str = format(h, 'b')

cnt = 2 ** (len(bin_str)) - 1

print(cnt)

Submission status: Accepted

Solution code:
import math

h = int(input())

dp = dict()
dp[1] = 1
def rec(parent):
    child = math.floor(parent / 2)
    if parent == 1:
        return 1
    elif child in dp:
        return 2 * dp[child] + 1
    else:
        return 2 * rec(child) + 1

print(rec(h))

Submission status: Accepted

Solution code:
import math
total = 0
a = 1
H = int(input())
H = math.floor(math.log2(H))
for i in range(H+1):
    total += a
    a = a * 2
print(total)

Submission status: Accepted

Solution code:
def c(h, memo):

    if h == 1:
        return 1

    if h in memo:
        return memo[h]

    num_of_attacks = 1 + c(h // 2, memo) + c(h // 2, memo)
    memo[h] = num_of_attacks
    return num_of_attacks


def main():
    
    h = int(input())
    
    memo = {}
    res = c(h, memo)
    print(res)


main()

Submission status: Accepted

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

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())
attack = 0
i = 0

while H > 1:
    H = int(H/2)
    attack += pow(2,i)
    i += 1

print(attack+pow(2,i))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

H = int(input())

candidate = []
for i in range(49):
    candidate.append(2**i)

candidate_array = np.array(candidate).reshape(-1, 1)

for i in range(49):
    if candidate_array[i, 0] > H:
        candidate_select = candidate_array[:i, 0]
        print(np.sum(candidate_select))
        break

Submission status: Accepted

Solution code:
H = int(input())
import math
if not math.log(H, 2).is_integer():
  H = 2 ** math.floor(math.log(H, 2))

n = H
while H > 1:
  H = round(H / 2)
  n += H
print(n)

Submission status: Accepted

Solution code:
H = int(input())

if H == 1:
    print(1)
else:
    e = 0
    count = 1
    while True:
        if H > 1:
            e += 1
            count += 2**e
            H = int(H/2)
        else:
            break
    print(count)

Submission status: Accepted

Solution code:
import math

H = int(input())

a = math.floor(math.log2(H)) + 1
b = 2 ** a - 1
print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
Point=1
for i in range(300):
    if H>1:
        H=H//2
        Point=Point+Point+1
#        print(Point)
#        print(H)
    else:
        print(Point)
        break

Submission status: Accepted

Solution code:
H=float(input())
layer=[1]
i=0
count=0
HP=int(H/2)
if HP<=0:
    count+=layer[0]
    print(count)
else:
    count+=layer[0]
    while HP>0:
        i+=1
        layer.append(layer[i-1]*2)
        count+=layer[i]
        HP=int(HP/2)
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[2**i for i in range(50)]
import math
x=0
while n>1:
    n=math.floor(n/2)
    x+=1
print(int(4*(2**(x-1))-1))

Submission status: Accepted

Solution code:
H=int(input())

counter=1
ans=0
while H!=1:
    H=int(H/2)

    counter=counter*2

    ans+=counter

#4   2,2 1,1,1,1
#6 3,3 1,1,1,1
#8 4,4 2,2,2,2 1,1,1,1,1,1,1,1,1,1


print(ans+1)

Submission status: Accepted

Solution code:
num = int(input())
i = 0
ans_L = [1]
while num!=1:
    num = num//2
    i += 1
    ans_L.append(2**i)

print(sum(ans_L))

Submission status: Accepted

Solution code:
H = int(input())

n = 1

def calc(h,n):
    a = h//2
    if a==1:
        n += 2
    else:
        n += 2*calc(a,n)
    return n


if H == 1:
    print(1)
else:
    ans = calc(H,n)
    print(ans)

Submission status: Accepted

Solution code:
from math import log2, pow

h = int(input())
n = int(log2(h))
print(sum([2 ** e for e in range(0, n + 1)]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import floor

h = int(input())

ans = 1
i = 0
while h != 1:
    i += 1
    h = floor(h/2)
    ans += 2**i

print(ans)

Submission status: Accepted

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

ans = 1

loop = math.floor(math.log2(h))

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

print(ans)