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:
#D
H = int(input())

def get_attack_num(n):
    if n == 1:
        return 1
    elif n == 2 or n == 3:
        return 3
    return get_attack_num(n//2) * 2 + 1

print(get_attack_num(H))

Submission status: Accepted

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

while H != 1:
    ans += 2 ** num
    num += 1 
    H = H // 2

ans += 2 ** num
print(ans)

Submission status: Accepted

Solution code:
from math import log2


def closest_power_of_2(x: int):
    return int(log2(x))


def attacks(x: int):
    return int(2 ** (log2(2 ** closest_power_of_2(x)) + 1) - 1)


if __name__ == '__main__':
    h = int(input())

    print(attacks(h))

Submission status: Accepted

Solution code:
h = int(input())

m =1
cnt=0
if h <=1:
    print(1)

elif h <=3:
    print(3)
else:
    while h >3:
        h = h //2
        cnt+=m
        m = m*2


    cnt=cnt+m*3
    print(cnt)

Submission status: Accepted

Solution code:
# Enter your code here. Read input from STDIN. Print output to STDOUT

import numpy as np
from sys import stdin


def get_result(data):
    cnt = 0
    quotient = data
    while quotient > 1:
        quotient = quotient // 2
        cnt += 1
    return 2**(cnt+1) - 1

if __name__ == '__main__':
    data = int(stdin.readline())
    result = get_result(data)
    print(result)

Submission status: Accepted

Solution code:
import math
h = int(input())
cnt = 1
result = 1

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

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

print(result)

Submission status: Accepted

Solution code:
h=int(input())
ans = 0
temp = 1
for i in range(10000):
  if h//2 == 0:
    ans += temp
    break
  else:
    h = h//2
    ans += temp
    temp *= 2
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

flag = 0
dp = []
dp.append([H,1])

for i in range(1,H):
    tmp0 = dp[i-1][0]//2
    tmp1 = dp[i-1][1]*2
    dp.append([tmp0,tmp1])
    if dp[i][0]==1:
        break

l = len(dp)
p = [dp[i][1] for i in range(l)]
ans = sum(p)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
i = 0
check = 1

while N >= check:
    i += 1
    check = 2**i
print(2**i-1)

Submission status: Accepted

Solution code:
import sys
import math

sys.setrecursionlimit(1000000000)

def dfs(hit):
    if (hit <= 1):
        return 1
    else:
        return 1 + dfs(math.floor(hit / 2)) * 2

H, = list(map(int, input().split()))
print(dfs(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
inp = int(input())

h = inp 
cnt = 0
while (h != 1):
    cnt += 1
    h = h / 2
cnt += 1
ans = (1 << (cnt)) -1
print ans

Submission status: Accepted

Solution code:
h = int(input())
attack = 0
binary = 1
while h!= 0:
    if h == 1:
        attack = attack + binary
        h = 0
    else:
        attack  = attack + binary
        h = int(h/2)
        if h > 0:
            binary = binary *2
print(attack)

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:
import math

a = int(input())
cnt = 1
rem = a
while rem > 1:
    rem = math.floor(rem/2)
    cnt += 1

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

Submission status: Accepted

Solution code:
import math

H=int(input())
C=0
while H!=0:
  H=math.floor(H/2)
  C+=1

print(2**C-1)

Submission status: Accepted

Solution code:
def main():
    h = int(input())

    i = 0

    while(h >= 1):
        h //= 2
        i += 1

    print(2**i-1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import fractions
input = sys.stdin.readline
H = int(input())
ans = 0
for i in range(100):
    if H == 0:
        print(ans)
        break
    H //= 2
    ans += 2**i

Submission status: Accepted

Solution code:
H = int(input())
#a,b = map(int,input().split())
#L = list(map(int,input().split()))
cnt = 0
cnt1 =0
num = 1
while H>1:
    H = H//2
    cnt =cnt+1
    cnt1 +=num
    num =2**(cnt)
print(cnt1 +num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=bin(int(input()))[2:]
L=len(H)
a_list=[2**i for i in range(L)]
print(sum(a_list))

Submission status: Accepted

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

L = int(np.log2(H))
K = ceil(np.log2(H))
if K == L:
    count = K
else:
    count = K - 1
L = 2 ** (count + 1) - 1

print(L)

Submission status: Accepted

Solution code:
n = int(input())
co = 0
for i in range(10**12):
  n = n/2
  co += 1
  if n < 1:
    break

ans = []
a = 1

for i in range(co):
  ans.append(a)
  a *= 2

print(sum(ans))

Submission status: Accepted

Solution code:
H = int(input())
memo = {1: 1}
def dfs(h):
  global memo
  memo[2] = 3
  if h in memo:
    return memo[h]
  memo[h] = dfs(h // 2) + dfs(h // 2) + 1
  return memo[h]
print(dfs(H))

Submission status: Accepted

Solution code:
def run():
  H = int(input())
  n = 0
  while H > 0:
    n += 1
    H //= 2
  print(2**n-1)
      
  
if __name__ == '__main__':
  run()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
h=int(input())
ans=0
n=math.ceil(math.sqrt(h))+1
for i in range(n):
    if h>=2**i:
        ans+=2**i
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(0, 10**9):
  if(2**i <= n and n < 2**(i+1)):
    print(2**(i+1) - 1)
    exit()

Submission status: Accepted

Solution code:
def  caracal(H):
    k = 0
    n_sum = 0
    while H >n_sum :
        n_sum += 2**k    
        # print("n_sum : k ",n_sum,k)
        k +=1
    
    return n_sum


H = input()
H = int(H)
# H =12
print(caracal(H))

Submission status: Accepted

Solution code:
H=int(input())

count=0
plusnum=1

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

print(plusnum+count)

Submission status: Accepted

Solution code:
H = int(input())
answer = 1
n = 1
if H == 1:
    print(1)
    exit()
while True:
    answer += 2**n
    if 2**n <= H and H < 2**(n+1):
        break
    n += 1

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
d = {}

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

h = int(input())

print(f(h))

Submission status: Accepted

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

while h > 0:
  h = h//2
  ans = ans + 2**roop
  roop += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())

H = int(input())

x = H
cnt = 0
while x != 1 :
  x //= 2
  cnt += 1
#print (cnt)

sum = 1
y = 1
for i in range(cnt) :
  sum += y*2
  y *= 2
  #print (sum)
print (sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

attack = 1
while h > 0 :
    h = h // 2
    attack *= 2

print(attack - 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import queue
import copy
import math
from collections import deque

h = int(input())

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

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

depth = math.log2(h)


waru = 0
target = h
while True:
    d, m = divmod(target, 2)
    target = d
    waru += 1
    if target == 1:
        break
    else:
        continue

d, m = divmod(h, 2)

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

print(ans)

Submission status: Accepted

Solution code:
# import itertools
# import math


def solve(H):
    ans_attack = 0
    hp = H
    enemy = 1

    while hp > 1:
        hp = hp // 2
        ans_attack = ans_attack + enemy
        enemy = enemy * 2

    return ans_attack + enemy


H = int(input())

print(solve(H))

Submission status: Accepted

Solution code:
h = int(input())

n = 0
while (h != 1):
    h = h // 2
    n += 1

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

Submission status: Accepted

Solution code:
import math
count = 1
def kaisu(H,Y):
    global count
    if H == 1:
        return True
    else :
        if kaisu(math.floor(H/2),Y * 2):
            count += Y * 2
            return True

H = int(input())
kaisu(H,1)
print(count)

Submission status: Accepted

Solution code:
t=int(input())
s=0
def kara(t,s):
    if t==1:
        s=s+1
        return 1
    else:
        t=int(t/2)
        s=s+1
    return kara(t,s)*2+1

print(kara(t,s))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)

import math

class Tree:
    def __init__(self, hp):
        self.hp = hp
        self.sons = []

    def split(self):
        return Tree(math.floor(self.hp/2)),Tree(math.floor(self.hp/2))
    

H = int(input())

num = 0
x = H
while x>1:
    x = math.floor(x / 2)
    num += 1


# ans = 1 + 2 + 4 + 8 + ..
ans = 0
for i in range(num+1):
    ans += 2**i

#ans += 2**num
print(ans)

Submission status: Accepted

Solution code:
H = int(input())
H_list = [H]
ans = 0
while H > 0:
  H = int(H / 2)
  H_list.append(H)
for i in range(1, len(H_list) - 1):
  ans += 2 ** i
print(ans + 1)

Submission status: Accepted

Solution code:
import sys
import math
read = sys.stdin.buffer.read #全てまとめて文字列として格納
readline = sys.stdin.buffer.readline # 一行読む
readlines = sys.stdin.buffer.readlines # 全行リストに格納
H = int(read())
if H == 1:
  print(1)
  exit()

EXP = math.floor(math.log(H,2))
print(str(int(2**(EXP+1)-1)))

Submission status: Accepted

Solution code:
h= int(input())
b = 0
while True:
    if 2**b <= h < 2**(b+1):
        #print(2**b,2**(b+1))
        print(2**(b+1)-1)
        break
    b += 1

Submission status: Accepted

Solution code:
import math

def main(H):
    res = 0
    count = 0
    val = H
    while 1 < val:
        val = math.floor(val/2)
        count += 1
    for i in range(count+1):
        res += 2**i
    print(res)

H = int(input())
main(H)

Submission status: Accepted

Solution code:
import math
n = int(input())
n_log = math.log(n,2)
n_log_2 = math.floor(n_log)
print(2**(n_log_2+1)-1)

Submission status: Accepted

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

Submission status: Accepted

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

    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
h = int(input())

n = 1
while h >= 2 ** n:
    n += 1
print(2 ** n - 1)

Submission status: Accepted

Solution code:
h = int(input())

n = 1
# 再帰関数の定義
def check(n, k):
  # 割った数が1以上の時
  if((k//2) >= 1):
    n += 1
    k = k // 2
    check(n, k)
  else:
    print(2**n - 1)
    
check(n, h)

Submission status: Accepted

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

Submission status: Accepted

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

print(temp)

Submission status: Accepted

Solution code:
#N, K = list(map(int, input().strip().split()))
#H = list(map(int, input().strip().split()))
H = int(input().strip())
attachs = {}

def needed_attach(value):
  #print(value)
  if value == 1:
    return 1
  else:
    if value in attachs:
      x = attachs[value]
    else:
      x = needed_attach(value // 2) * 2 + 1
      attachs[value] = x
    return x

print(needed_attach(H))

Submission status: Accepted

Solution code:
import math

h = int(input())

c = math.floor(math.log2(h))+1

print(2**c - 1)

Submission status: Accepted

Solution code:
H = int(input())

import math

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

Submission status: Accepted

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

if H==1:
    print(1)
    
else:
    while H!=0:
        H=H//2
        at+=1
    ans=1
    preans=1
    for i in range(2,at+1):
        ans+=preans*2
        preans=preans*2
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

H = int(input())
"""2
def attack(x,n):
  if x == 1:
    return 2**n
  else:
    return attack(x//2,n+1) + 2**n

print(attack(H,0))

exit()
"""

attack_count = 0
attack_time = 0

while(H > 0):
  H = H // 2
  attack_count += 2**attack_time
  attack_time+=1

print(attack_count)

Submission status: Accepted

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

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

# print(d)

ans = 2 ** (d + 1) - 1
print(ans)

Submission status: Accepted

Solution code:
import math

def main():
    n = int(input())

    node = math.floor(math.log2(n)) + 1

    print(2 ** node - 1)




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
H = int(input())

ans = 0
rate = 1

while H != 0:    
    ans += rate
    rate = rate * 2
    H = H // 2

print(ans)

Submission status: Accepted

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

print(steps(a))

Submission status: Accepted

Solution code:
H = int(input())

n = 0
while True:
    if 2 ** n <= H < 2 ** (n+1):
        break
    n += 1
if n == 0:
    ans = 1
else:
    ans = 1
    for i in range(1, n+1):
        ans += 2**i

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

A = []
count = 0

while(H>0):
  count += 1
  A.append(H)
  H = H//2

ans = 0
temp = 1
for i in range(count):
  if(i==0):
    ans += temp
  else:
    temp = temp*2
    ans += temp
    
print(ans)

Submission status: Accepted

Solution code:
H=int(input())
T=H
i=0
s=0
if H==1:
    print(1)
else:
    while(T>1):
        T=T//2
        i+=1
        s+=2**i
    print(s+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
H = int(input())

result = 0
attack = 1
loop = 1
while H > 1:
    H = H // 2
    loop += 1

arr = [2**i for i in range(loop)]
print(sum(arr))

Submission status: Accepted

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

Submission status: Accepted

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

def c(i):
    if i == 1: return 1
    elif i == 0: return 0
    else: return 1 + 2*c(i//2)
print(c(h))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

def attack(h):
    if h <= 1:
        return 1
    f = {}
    n = 1
    while (h // 2 > 1):
        h = h // 2
        n += 1
    for i in range(n):
        f[i] = 0
    f[0] = 1
    for i in range(1, n + 1):
        f[i] = f[i-1] * 2 + 1
    return f[n]

if __name__ == '__main__':
    h = int(stdin.readline().rstrip())
    print(attack(h))

Submission status: Accepted

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
def main():
    H = int(input())

    bin_H = str(format(H, 'b'))
    length = len(bin_H)

    ans = str(1) * length
    print(int(ans, 2))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h = int(input())

cnt = 1
res = 0

while h > 0:
    h = h//2
    res += cnt
    cnt *= 2

print(res)

Submission status: Accepted

Solution code:
import math

ans = 0
for i in range(1, math.floor(math.log2(int(input()))) + 1):
    ans += 2 ** i
print(ans + 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
H_new = {int(input()):1} # 体力:匹数
ans = 0

while True:
    X = H_new
    H_new = {}
    for k, v in X.items():
        if k == 1:
            ans += v
        else:
            ans += v
            h = int(k//2)
            if h in H_new:
                H_new[h] = H_new[h]+v*2
            else:
                H_new[h] = v*2
    if len(H_new) == 0:
        break
    
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

x = H
y = 0
r = 0
while True:
    if x == 1:
        break
    x = x // 2
    y += 1
    r += 2**y

print(r + 1)

Submission status: Accepted

Solution code:
H = int(input())
res = 0
for i in range(40):
    if 2**i <= H < 2**(i+1):
        for j in range(0, i+1):
            res = res + 2**j
print(res)

Submission status: Accepted

Solution code:
h = int(input())
a = 1
w = 'no'
while w == 'no':
    if h//2**a == 0:
        w = 'yes'
    else:a += 1
print(2**a-1)

Submission status: Accepted

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

# process
t = H
i = 1
while t > 1:
    t //= 2
    i += 1

#output
print(2**i-1)

Submission status: Accepted

Solution code:
H=int(input())
N=1
while 2**N<=H:
  N+=1
ans=0
for i in range(N):
  ans+=2**i
print(ans)

Submission status: Accepted

Solution code:
import math
import time

if __name__ == '__main__':
    a = int(input())
    count = 0
    while(a != 1):
        count += 1
        a = math.floor(a / 2)
    sum_d = 0
    d = 1
    for i in range(count):
        sum_d += 2 ** d
        d += 1
    print(sum_d + 1)

Submission status: Accepted

Solution code:
H = int(input())

def func(H):
    # +1して半分にする
    if H == 1:
        return 1
    ans = 1
    # print("H/2:", int(H/2))
    ans += 2 * func(int(H/2))
    # print(f"at H: {H}, ans: {ans}")
    return ans

print(func(H))

Submission status: Accepted

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

H = int(input())

depth = 0
ans = 0

while H > 1:
    ans += 1 * (2 ** depth)
    H //= 2
    depth += 1

ans += 1 * (2 ** depth)

print(ans)

Submission status: Accepted

Solution code:
import math
h=int(input())
cnt=1
ans = 1
if h==1:
    print(1)
else:
    for i in range(h):
        h= math.floor(h/2)
        if h <= 1:
            cnt += i
            break
    for j in range(1,cnt+1):
        ans+= 2**j
    print(ans)

Submission status: Accepted

Solution code:
i = int(input())

stage = 1
kai = 1

while stage*2 <= i:
    stage = stage*2
    kai += 1

stage = stage // 2
kai -= 1

r = 0
while kai > 0:
    r += 2 ** kai
    kai -= 1

print(r + 1)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys

H = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input())

counter = 1
result = 0

while N!=1:
    N = N//2
    result += counter
    counter *= 2
result += counter
print(result)

Submission status: Accepted

Solution code:
import math

h = int(input())
if h == 1:
    print(1)
else:
    n = math.floor(math.log2(h))
    print(2**(n+1)-1)

Submission status: Accepted

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

print(2**cnt*2-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

h = int(input().rstrip())

a = int(math.log2(h))

sum = 0

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

print(sum)

Submission status: Accepted

Solution code:
print(2 ** len('{0:b}'.format(int(input()))) - 1)

Submission status: Accepted

Solution code:
H=int(input())
cnt,ans,tmp=1,1,1
while tmp<=H:
    if tmp*2 <= H:
        ans+=2**cnt
        cnt+=1
        tmp=tmp*2
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
h = int(input())
ans = 0
for i in range(41):
    if 2**i <= h < 2**(i+1):
        for k in range(i+1):
            ans += 2**k
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
H=int(input())
ans=0
k=0
while H >0:
    H=H//2
    k+=1
    ans+=math.pow(2,k-1)
print(int(ans))

Submission status: Accepted

Solution code:
import math

h = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

h = int(input())
n = 1
result = n
while True:
  if h > 1:
    h = math.floor(h/2)
    n = n * 2
    result += n
  else:
    print(result)
    break

Submission status: Accepted

Solution code:
import sys
import math

h=int(input().strip())

atk=0
mst=1

while(1):
    if h==1:
        atk+=mst
        break
    else:
        h=(math.floor(h/2))
        atk+=mst
        mst=mst*2

print(atk)

Submission status: Accepted

Solution code:
import math
def hanbun(H):
  ans=(H/2)
  return math.floor(ans)
H=int(input())
count=0
temp=H
while temp!=0:
  temp=hanbun(temp)
  count=count+1
print (2**count-1)

Submission status: Accepted

Solution code:
import math
s = list(map(int, input().split()))
l=int(math.log2(s[0]))
print(int(2**(l+1)-1))

Submission status: Accepted

Solution code:
import math
import sys

H = int(input())

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

times = 0
while H > 1:
    H = math.floor(H/2)
    times += 1

ans = 1
tmp = 1
for i in range(0,times):
    tmp = tmp*2
    ans = ans + tmp
    
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

cnt = 1
hit_point = 1
base = 1
while H > hit_point:
    base *= 2
    cnt += base
    hit_point *= 2
    if hit_point * 2 > H:
        break

print(cnt)

Submission status: Accepted

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

H = int(input().split()[0])
c = 0
now_h = H
i = 0
while now_h >= 1:
    now_h = now_h // 2
    if i == 0:
        c += 1
    else:
        c += 2 ** i
    i += 1

ans = c
print(ans)

Submission status: Accepted

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

h = int(input())
cnt = 0
while h > 1:
    h //=2
    cnt+=1
if cnt==0:
    print(1)
else:
    print(2**(cnt+1)-1)

Submission status: Accepted

Solution code:
# your code goes here
def nextPowerOf2(n): 
	count = 0; 

	# First n in the below 
	# condition is for the 
	# case where n is 0 
	if (n and not(n & (n - 1))): 
		return n 
	
	while( n != 0): 
		n >>= 1
		count += 1
	
	return 1 << count; 
# Python3 program to find whether a number 
# is power of 2 or not 

# Function to check whether a 
# number is power of 2 or not 
def ispowerof2(num): 

	if((num & (num - 1)) == 0): 
		return 1
	return 0

# This code is contributed by 
# Sanjit_Prasad 

n=int(input())
if(n==1):
	print(1)
else:
	if(ispowerof2(n)):
		print(2*n-1)
	else:
		k=nextPowerOf2(n)
		k=k//2
		print(2*k-1)

Submission status: Accepted

Solution code:
# coding:utf-8

H = int(input())

pw = 2

if H == 2 or H ==3:
    print(3)
else:
    while H >= pw:
        pw = pw * 2
    print(pw - 1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
h = int(input())

binary = len(bin(h))-2

print(2**binary-1)

Submission status: Accepted

Solution code:
hp = int(input())
import math
x = int(math.log(hp,2))

res = 0
for i in range(x + 1):
    res += 2 ** i
    
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

power_2 = 1
i = 0
while power_2 <= H:
    power_2 = power_2 * 2
    i += 1

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

print(num)

Submission status: Accepted

Solution code:
import math

h = int(input())

hn = int(math.log2(h))

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

print(r)

Submission status: Accepted

Solution code:
H = int(input())


def div2(x):
    if x > 1:
        return div2(int(x/2)) * 2 + 1
    else:
        return 1


print(div2(H))

Submission status: Accepted

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

count = 0
count = int(math.log2(H))

total = 0
total = int((1 - (2**(count + 1)))/(1 - 2))
print(total)

Submission status: Accepted

Solution code:
H=int(input())

sum=0
num=1
h=H

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

time = 0
now = H
pow2list = [2**i for i in range(50)]

import math
a = math.log(now, 2)
print(sum(pow2list[0:math.floor(a+1)]))

Submission status: Accepted

Solution code:
import math
H = int(input())
a = math.log(H, 2)
ans = 0

b = int(a)
for i in range(b + 1):
    ans += 2 ** i
print(ans)

Submission status: Accepted

Solution code:
import math

h = int(input())

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

attack = 0

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

print(attack)

Submission status: Accepted

Solution code:
H=int(input())

def func(a):
    res=0
    for i in range(a):
        res+=int('1'+'0'*i,2)
    return res

bin_H=format(H,'b')
len_bin_H=len(bin_H)
s_bin='1'+'0'*(len_bin_H-1)

ans=func(len_bin_H)
print(ans)

Submission status: Accepted

Solution code:
r=int(input())
p=0
for i in range(100):

    if 2**p<=r and r<2**(p+1):
        break
    p+=1
        
print(2**(p+1)-1)

Submission status: Accepted

Solution code:
import math
H = int(input()) #HP
L = []
X = H
i = 0
while X != 1:
    X = math.floor(X/2)
    i += 1
print(int((1-2**(i+1))/(1-2)))

Submission status: Accepted

Solution code:
H = int(input())

def find_pow(x):
    if x==1:
        return 0
    else:
        res = 0
        t = 1
        while(t <= x):
            t *= 2
            res +=1
    return res-1

p = find_pow(H)
res = 0
for i in range(p+1):
    res +=2**i
print(res)

Submission status: Accepted

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations

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

def intinput():
    return int(input())

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

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas



H = intinput()

n = floor(log2(H))

ans = int((1-(2**(n+1)))/(1-2))


# 出力
print(ans)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math

H = int(input())


def main():
    split_cnt = int(math.log2(H))

    atk_cnt = 0

    for i in range(split_cnt + 1):
        atk_cnt += 2 ** i
    return atk_cnt


ans = main()

print(ans)

Submission status: Accepted

Solution code:
h = int(input())

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

ans = 1
cur = 1
for _ in range(1, cnt):
  cur *= 2
  ans += cur
  
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

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

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

Submission status: Accepted

Solution code:
import math
n=int(input())
j=math.floor(math.log(n,2))
a=0
for i in range(0,j+1):
    a=a+pow(2,i)
print(a)