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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import deque
import math


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


def inputInt():
  return int(input())


def main():
  H = inputInt()
  cnt = 0
  ans = 0
  while H:
    H = H >> 1
    ans += 2 ** cnt
    cnt += 1

  return ans


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

Submission status: Accepted

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

import numpy as np

cnt=0
for i in range(100):
    if H<2**(i+1):
        break
    else:
        cnt+=1
        
if cnt == 0:
    print(1)
else:    
    print(np.sum([2**i for i in range(cnt+1)]))

Submission status: Accepted

Solution code:
H = int(input())

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

print(count)

Submission status: Accepted

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 h!=1:
    h = h//2
    i += 1
    ans_L.append(2**i)

print(sum(ans_L))

Submission status: Accepted

Solution code:
h = int(input())
list_1 = []
ans = 0
cnt = 0
if h == 1 :
  ans = 0
else :
  cnt += 1
  list_1.append(cnt)
  while h // 2 != 1: 
    cnt += 1
    list_1.append(cnt)
    h = h // 2

for i in list_1 :
  if i == 1:
    ans += 2
  else :
    ans += 2**i

print(ans+1)

Submission status: Accepted

Solution code:
import math
h = int(input())
c = 0
while h > 1:
    h /= 2
    c += 1
if h == 1:
    print(int("1"*(c+1),2))
else:
    print(int("1"*c,2))

Submission status: Accepted

Solution code:
import math
h=int(input())
h_now=h
num_now=1
ans=0
for i in range(50):
    if h_now==1:
        break
    else:
        h_now=math.floor(h_now/2)
        ans+=num_now
        num_now=num_now*2

ans+=num_now
print(ans)

Submission status: Accepted

Solution code:
h = int(input())
count2 = 0
if h //2 >1:
    while h // 2 > 1:
        count2 += 1
        h= h//2
    if h //2 == 1:
        count2 += 1
elif h // 2 == 1:
    count2 = 1
elif h // 2 == 0:
    count2 = 0

sig = 0
for i in range(count2):
    sig += 2 ** i

ans = 2**count2 + sig
print(ans)

Submission status: Accepted

Solution code:
h=int(input())

for i in range(10000000000):
  if 2**i>h:
    print(2**i-1)
    break

Submission status: Accepted

Solution code:
import math

H = int(input())

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
H = int(input())

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

ans = 1
while count > 0:
    ans = ans + 2 ** count
    count -= 1

print(ans)

Submission status: Accepted

Solution code:
h=int(input())
h1=h
icnt=0
for i in range(1000):
    h1=h1//2
    icnt=icnt+1
    if h1<1:
        break
    
s=int(2**icnt)-1
print(s)

Submission status: Accepted

Solution code:
H = int(input())

res = 0
k = 0

while(H != 0):
    H = (int)(H/2)
    res += 2 ** k
    k += 1

print(res)

Submission status: Accepted

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

for i in range(1, 41):
    if (2 ** i) > hp:
        n_bi = i - 1
        break

ans = (2 ** (n_bi + 1)) - 1
print(int(ans))

Submission status: Accepted

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

print(2 ** count - 1)

Submission status: Accepted

Solution code:
h = int(input())

import math

if h == 1:
    print(1)

else:
    n_attacks = 0
    while h / 2 >= 1:
        n_attacks += 1
        h = math.floor(h/2)

    gsum = 1

    for x in range(n_attacks):
        gsum += 2 ** (x + 1)
        
    print(gsum)

Submission status: Accepted

Solution code:
def rec(l):
    if l<=0:
        return 0
    if l==1:
        return 1
    else:
        return 1+2*rec(l//2)
x=int(input())
print(rec(x))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = input()

def attack_sum():
	X = H
	number_attack = 0
	while X > 0:
		number_attack *= 2
		number_attack += 1
		X = X // 2
	return number_attack		

ans = attack_sum()
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import math


def main(inp):
    h = int(inp)

    hp = h
    num_enemy = 1
    num_attack = 0
    while hp >= 1:
        hp, num_enemy, this_attack = attack(hp, num_enemy)
        num_attack += this_attack
    return num_attack


def attack(enemy_hp, num_enemy):
    num_attack = num_enemy
    enemy_hp = math.floor(enemy_hp / 2)
    num_enemy *= 2
    return enemy_hp, num_enemy, num_attack


if __name__ == '__main__':
    input_line = stdin.readline().rstrip()
    ret = main(input_line)
    print(ret)

Submission status: Accepted

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

for i in range(H):
    if 2 ** i > H:
        break
    pow_num += 1

attack_num = 0
for i in range(pow_num):
    attack_num += 2 ** i

print(attack_num)

Submission status: Accepted

Solution code:
H = int(input())
if H==1:
  print(1)
elif 2 <= H and H <= 3:
  print(3)
elif 4 <= H and H <= 7:
  print(7)
else:
  for i in range (1,43):
    if 2**(i-1)<=H and H <2**(i):
      print(2**(i)-1)
    else:
      pass

Submission status: Accepted

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

roop=int(math.log2(H))

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

Submission status: Accepted

Solution code:
h = int(input())
tem = 1
while h/2 > 1:
    tem+=1
    h = h/2
result = 1
if h==2:
    for i in range(1,tem+1):
        result += 2**i
else:
    for i in range(1,tem):
        result += 2**i
print(result)

Submission status: Accepted

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

H=int(input())
print(enemy_counter(H,0))

Submission status: Accepted

Solution code:

h = int(input())

count = 1
result = 1

while True:
    if h >= 2 ** count:
       result += 2 ** count
       count += 1
    else:
        break

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())
A=1
if H==1:
    print(1)
else:
    while H>=A:
        A*=2
    print(A-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
h = format(h, 'b')
t = h.find('1')
l = len(h)
ans = 2 ** l - 1
print(ans)

Submission status: Accepted

Solution code:
import sys

H = int(input())

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

h = 1

while(True):
  if 2**h <= H < 2**(h+1):
    break

  h += 1

ans = 3

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

for k in range(1, h+1):
  if k == 1:
    continue

  ans += 2**k

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

H = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
h = [int(input())]
a = 1
x = False
while(x == False):
  if h[0] < 1:
    x = True
    break
  h = list(map(lambda x: x / 2, h))
  a = a*2
print(a-1)

Submission status: Accepted

Solution code:
import math
import numpy as np

H = int(input())

for i in range(1000):
  if 2**i > H:
    num = i-1
    break
dp = 1
for j in range(num):
  dp = 2*dp+1
print(dp)

Submission status: Accepted

Solution code:
import math

H = int(input())

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

root = math.floor(math.log2(H))

total = 1
#print(math.log2(H))
mem = [1 for _ in range(root+1)]

for i in range(1, root+1):
  mem[i] = mem[i-1] * 2
  total += mem[i]
  
print(total)

Submission status: Accepted

Solution code:
#!python3.4.3

import math

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

Submission status: Accepted

Solution code:
h = int(input().strip())

for i in range(41):
    if 2**(i+1) > h and h >= 2**i:
        n = i + 1
        break
print(2**n - 1)

Submission status: Accepted

Solution code:
# cook your dish here
from math import log2,floor
n=int(input())
k=floor(log2(n))
if int(k)==k:
    print(pow(2,k+1)-1)
else:
    print(pow(2,k)-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
power2 = 1
while(H >= power2):
  ans += power2
  #power2**2
  power2 *= 2
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

ch=1
total=1

while 1:
    if h < ch:
        break
    else:
        ch*=2
        total+=1

print(ch-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
h=int(input())
def cal(x):
  if x==1:
    return 1
  else:
    return 1+2*cal(math.floor(x/2))
print(cal(h))

Submission status: Accepted

Solution code:
H=int(input())

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

Submission status: Accepted

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


def solve(H: int):
    ans = 2 ** f(H) - 1
    print(ans if H > 1 else 1)
    return


def f(H, dep=1):
    half_h = H // 2
    dep += 1
    return f(half_h, dep) if half_h > 1 else dep


# 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:
H = int(input())
#H = 2
N = 0
while H > 1:
    H = H // 2
    # print(H)
    N += 1

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

print(ans)

Submission status: Accepted

Solution code:
def Step(i):
	if i == 1 :
		return 1
	a = 2 * Step(i//2)
	return a+1

H = int(input())
print(Step(H))

Submission status: Accepted

Solution code:
H = int(input())

def func(H):    
    if H == 1:
        return 1
    H_next = H // 2
    return func(H_next) * 2 + 1

print(func(H))

Submission status: Accepted

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

H = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

count = 0
enemy = H
ans = 0

while(enemy >= 1):
    enemy /= 2
    count += 1

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

print(ans)

Submission status: Accepted

Solution code:
h = int(input())

a = h
num = 0
total = 0

while a >= 1:
  if num == 0:
    num += 1
  else:
    num = num * 2
  total += num
  a = a // 2

print(total)

Submission status: Accepted

Solution code:
h=int(input())

result=1
count=1

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

print(2**count-1)

Submission status: Accepted

Solution code:
import math

h = int(input())
h_list = [h]

ht = h
i=0
while ht>0:
  ht = math.floor(ht/2)
  i = i+1

print(2**i - 1)

Submission status: Accepted

Solution code:
import math

h = int(input())


def nearpow2(n):
    k = int(math.log2(n))
    return k

print((2 ** nearpow2(h) - 1) * 2 + 1)

Submission status: Accepted

Solution code:
import math
def twosq(no):
  n = int(math.log2(no))
  tot = 0
  for i in range(1, n+1): tot+=2**i
  return tot+1

x = int(input())
print(twosq(x))

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a=int(input())
pow_count = 0
count = 1
if a == 1:
    print(count)
else:
    while a >= 2:
        a /= 2
        pow_count += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

def hantei(X, N):
    if X != 1:
        X_new = np.floor(X/2)
        flag = True
    else:
        X_new = 0
        flag = False
    return X_new, N*2, flag

flag = True
N = 1
count = 0
while flag:
    count += N
    X, N, flag = hantei(X, N)     
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
cnt=1
if n==1:
  print(1)
else:  
  while n>0:
    n//=2
    cnt*=2
  print(cnt-1)

Submission status: Accepted

Solution code:
# なんか適当にdpをこねくりまわす
# （どうしてできたんだろうね)

h = int(input())

dp = {}
dp[1] = 1


def f(x):
    if x in dp:
        return dp[x]
    if x == 1:
        return 1
    tmp = f(x // 2) + 1
    dp[x] = tmp
    tmp += tmp - 1
    return tmp


print(f(h))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
from math import log2
print(sum([2**n for n in range(int(log2(h))+1)]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

H = int(input())

cnt = 0
p = 0
r = 0
h = H
while h > 1:
    p = 2 ** r
    r += 1
    cnt += p
    h = math.floor(h / 2)

p = 2 ** r
cnt += p
print(cnt)

Submission status: Accepted

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

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
H = int(input())

d = {}
d = {1:1}
def f(n):
    if(d.get(n) != None):
        return d[n]
    buf = f(int(n/2)) + f(int(n/2)) + 1
    d[n] = buf
    return buf

print(f(H))

Submission status: Accepted

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

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

print(helper(H))

Submission status: Accepted

Solution code:
import math

h = int(input())
d = int(math.log2(h))
t = 0
for i in range(d+1):
    t += 2**i
print(t)

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:
import math
N=int(input())
n=math.floor(math.log2(N))

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

Submission status: Accepted

Solution code:
H = int(input())

ans = 0

for i in range(100):
    if(H < 2**i):
        max_range = i
        break
    ans += 2**i

print(ans)

Submission status: Accepted

Solution code:
H=int(input())

import math

n=math.ceil(math.log2(H+1))
m=2**(n-1)
ans=2*m-1
print(ans)

Submission status: Accepted

Solution code:
a = int(input())
i = 0
j = 0

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

print(j)

Submission status: Accepted

Solution code:
import math

H = int(input())
x = 0
buf = 1
for i in range(60) :
    if 2**i <= H and H < 2**(i+1) :
        x = i
        break

for j in range(x) :
    buf = 2*buf+1

print(buf)

Submission status: Accepted

Solution code:
import math

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

while x > 1:
    x = math.floor(x/2)
    cnt += 1

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

Submission status: Accepted

Solution code:
a = int(input())
s = str(bin(a))[2:]

print(2**len(s)-1)

Submission status: Accepted

Solution code:
if __name__=="__main__":
    h = int(input())
    
    cnt = 0
    cnt_div = 0
    while h > 1:
        h = int(h/2)
        cnt += 2**cnt_div
        cnt_div += 1
        #print("cnt_div, h, cnt= {}, {}, {}".format(cnt_div, h, cnt))

    print(cnt + 2**cnt_div)

Submission status: Accepted

Solution code:
N = int(input())
for k in range(40):
    if N >= 2**k and N < 2**(k+1): 
        print(2**(k+1)-1)

Submission status: Accepted

Solution code:
H = int(input())
num = 1
ans = 1
if H == 1:
    ans = 1
else:   
    for _ in range(50):
        H //= 2
        num *= 2
        ans += num
        if H == 1:
            break
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

cnt = -1
temp_h = H
while temp_h > 0:
    temp_h //= 2
    cnt += 1

print(pow(2, cnt+1)-1)

Submission status: Accepted

Solution code:
def divide(a):
  count = 0
  ans = 1
  while int(a/2) != 0:
    count += 1
    ans += 2**count
    a /= 2
  return ans

h = int(input())
print(divide(h))

Submission status: Accepted

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

#H  2^n <= H < 2^n+1
n = int(math.log2(H))

ans = 1
for i in range(1, n+1):
    # print("2**i:", 2 ** i)
    ans += 2 ** i

print(ans)

Submission status: Accepted

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

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

  for j in range(cnt+1):
      s += 2 ** j

  print(s)

Submission status: Accepted

Solution code:
h = int(input())


for x in range(10000000000):
    if h < 2 ** x:
        print((2 ** x) - 1)
        break

Submission status: Accepted

Solution code:
def main():
    h = int(input())
    summ = 0
    bun = 1
    hh = h
    while(True):
        if hh <= 1:
            summ += bun
            break
        else:
            hh  = hh // 2
            summ += bun
            bun *= 2
    print(summ)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
def touhi(a,r,n):
    return a*(pow(r, n) - 1)//(r-1)
H = int(input()) 
n = math.floor(math.log2(H))+1
print(touhi(a=1, r=2, n=n))

Submission status: Accepted

Solution code:
h=int(input())

a=1
b=0
ans=0
for i in range(1,41):
       if h<a:
              break
       ans+=a
       a=a*2
       b+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a=1
z=0
while a<=n:
  a*=2
  z+=1
c=0
#print(a,z)
for i in range(0,z):
#  print(i)
  c+=2**i
print(c)

Submission status: Accepted

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

l = 1
num = 0

while(H>=1):
        num+=l
        H = H//2
        l*=2

print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
resd = {}
def A(h):
    if h == 1:
        return 1
    else:
        if h in resd:
            return resd[h]
        else:
            resd[int(h/2)] = A(int(h/2))*2+1
            return resd[int(h/2)]

H = int(input().strip())
print(A(H))

Submission status: Accepted

Solution code:
H=int(input())
ans=1
bycount=0
count=0
byby=0

while H>1:
    H=int(H/2)
    bycount+=1

    if H==1:
        break
while bycount!=0:
    ans+=2**bycount
    bycount=bycount-1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

lists = []
lists.append([N])

index = 1 * 2
point = N // 2
sum = 1
while point != 0:
  sum = sum + index
  index = index * 2
  point = point // 2

print(sum)

Submission status: Accepted

Solution code:
h = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
import math

def solve(h):
    devide = math.floor(math.log2(h))
    if h == 1:
        return 1

    if devide == 1:
        return 3
    if devide >= 2:
        num_of_ones = 2 ** devide


        return num_of_ones + sum_of_touhi(devide,1,2)

def sum_of_touhi(n,a,r):
    return ((a * ((r ** n) - 1)) // (r - 1))




def main():
    h = int(input())
    print(solve(h))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

attack = 0
monsters = 1
while H > 1:
    H = math.floor(H / 2)
    monsters *= 2
attack += (monsters * 2)
attack -= 1
print(attack)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = 0
num = 1
count = 0

H = int(input())

while (True):
  if H < 1:
    break
  
  count += num
  
  H /= 2
  num *= 2
  
print(count)

Submission status: Accepted

Solution code:
num = int(input())

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

print(result)

Submission status: Accepted

Solution code:
H=int(input())
import math
count=1
j=0
a=True

while a==True:
    if math.floor(H/2)!=0:
        H=math.floor(H/2)
        count=count+1
    else:
        a==False
        break

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

print(j)

Submission status: Accepted

Solution code:
start = int(input())

count = 0

while start != 0:

    if start % 2 == 0:
        tmp = start / 2
        
    else:
        tmp = (start - 1) / 2
    
    start = tmp
    count += 1


print(2**(count) - 1)

Submission status: Accepted

Solution code:
h = int(input())

ans = int(0)

for i in range(100000):
  n = 2**i
  if n > h:
    ans = 2**i - 1
    print(ans)
    break

Submission status: Accepted

Solution code:
from math import floor,log2
h = int(input())
d = floor(log2(h))
c = 1
for i in range(0,d):
  c += 2 ** (d-i)

print(c)

Submission status: Accepted

Solution code:
import math
def resolve_d():
    H = int(input())
    x = int(math.log(H, 2))
    print((2**(x+1))-1)
resolve_d()

Submission status: Accepted

Solution code:
import math

H = int(input())

A = int(math.log(H,2))
print(2**(A+1) -1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def num_attack(H, N):
  if(H == 1):
    N += 1
  else: 
    N += 2*num_attack(int(H/2),N)
    N += 1
  return N

H = int(input())
N = num_attack(H, 0)
print(N)

Submission status: Accepted

Solution code:
h = int(input())
if h==1:
    print(1)
u=2
o=4
for i in range(10*5):
    if u<=h<o:
        print(o-1)
        exit()
    else:
        u=u*2
        o=o*2

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    H = int(input())

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


main()

Submission status: Accepted

Solution code:
import math

h = int(input())
cnt = 0
depth = 0

while True:
  if h == 1:
    cnt += 2**depth
    break
  else:
    cnt += 2**depth
    depth += 1
    h = math.floor(h/2)

print(cnt)

Submission status: Accepted

Solution code:
h = int(input())

a = 0
c = 0

while h > 0:
    h = int (h/2)
    a = a + 1
    c = c + 2**(a-1)

print (c)

Submission status: Accepted

Solution code:
import math
h = int(input())
logh = math.log2(h)
r = 0
for i in range(1,int(logh) + 2):
  h = h//2
  if h ==0:
    r = i
    break
print(2**r-1)

Submission status: Accepted

Solution code:
def calc_dan(h):
    hh = h
    dan = 0
    while hh > 1:
        hh = hh // 2
        dan += 1
    return dan

def main():
    H = int(input())
    dan = calc_dan(H)
    answer = 1
    for i in range(1, dan + 1):
        answer += (2 ** i)
    print(answer)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

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

print(sum)

Submission status: Accepted

Solution code:
# 再帰関数で計算
import sys

def caracal(H,count,separate_number):
	if H == 1:
		return count
	else:
		H = int(H/2)
		count = count + (separate_number*2)
		# 攻撃時の分離数
		separate_number = separate_number * 2 
	return caracal(H,count,separate_number)




H = int(input())
print(caracal(H,1,1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def convert_2(num):
      
    count = 0

    while (num >= 1):
        num /= 2
        count += 1
    
    return(count)

HP = int(input())
cnt = convert_2(HP)
answer = 2**cnt - 1
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

final_monster_num = 2 ** count
ans = final_monster_num * 2 - 1 

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    h = int(input())
    flag = True
    num = h
    count = 0

    while flag:
        count += 1
        num = int(num / 2)
        if num == 0:
            flag = False

    print(2 ** count - 1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

h = input()
h = int(h)

n = 1
for i in range(math.floor(math.log2(h))):
  n += 2 ** (i+1)

print(n)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
h = int(input())

temp = 0
for i in range(1, 50):
    temp = 2**i
    if temp <= h:
        continue
    else:
        N = i
        break

#二乗の和を繰り返す回数
ans = 0
for i in range(N):
    ans += 2**i
    #print("ans: ", ans)
print(ans)

Submission status: Accepted

Solution code:
import math

h = int(input())
num = int(math.log2(h))

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

print(2**count_dev2 - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=len(bin(int(input())))-3
if n==0:
    print(1)
elif n==1:
      print(3)
else:
    a=1
    for i in range(1,n+1):
        a+=2**i
    print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

  from math import log2
  deep = int(log2(H))+1
  ans = 0
  for d in range(0,deep):
    ans += 2**d

  print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math

input = sys.stdin.readline

def main():
    H = int(input())
    print(2 ** int((math.log(H, 2)) + 1) - 1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h=int(input())
beki = 0
sum_list = []
while 2 ** beki <= h:
  sum_list.append(2 ** beki)
  beki += 1
  
print(sum(sum_list))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
h=int(input())  #数値入力 「N」だけの入力のとき

n = 0
while(h != 0):
    h = h >> 1
    n+=1

print((2**n) -1)

Submission status: Accepted

Solution code:
import math
h = int(input())
n = math.floor(math.log(h)/math.log(2.0))
r = 2 ** (n+1) - 1
print(r)

Submission status: Accepted

Solution code:
import numpy as np
H = int(input())
count = 0
ans = 0

while True:
    H = np.floor(H/2)
    count += 1
    if H == 0:
        print(2 ** count - 1)
        break

Submission status: Accepted

Solution code:
h = int(input())

import math as m
a = int(m.log2(h))

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

Submission status: Accepted

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

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