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:
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve0():
    h = read_int()
    m = 1
    c = 1
    while h > 1:
        h = h//2
        m *= 2
        c += m
    return c

def solve():
    h = read_int()
    m = 1
    c = 0
    while h >= 1:
        c += m
        h = h//2
        m *= 2
    return c


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

def solve(h):
    if h == 1:
        return 1
    return solve(math.floor(h/2))*2 + 1

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    h = int(input())
    i = int(2*2**math.floor(math.log2(h))-1)
    print(i)

    # 25
    # 12 12
    # 6 6 6 6
    # 3 3 3 3 3 3 3 3
    # 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    #

    # 31
    # 15 15
    # 7 7 7 7
    # 3 3 3 3 3 3 3 3
    # 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

h = int(input())
l = int(math.log(h, 2))

ans = math.pow(2, l+1) - 1
print(int(ans))

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(solve(int(input())))

Submission status: Accepted

Solution code:
h=int(input())
bin_str = format(h, 'b')
cost = 0
x = [1,0] 
l = len(bin_str)
if h >= 2:
  for i in range(0,l-1):
    cost = cost + (x[int(bin_str[l-i-1])])*2**i
print(h+cost)

Submission status: Accepted

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

print(count - 1)

Submission status: Accepted

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

#等数列の和

a = 1
r = 2
n = 1 + int(math.log2(H))

print(int(a*(1-r**n)/(1-r)))

Submission status: Accepted

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

print(count - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(K):
    if K==1:
        return 1
    return 1+solve(K//2)*2
print(solve(int(input())))

Submission status: Accepted

Solution code:
H=int(input())
step=0;
while H>0:
    H=H//2
    step+=1 
print(pow(2,step)-1)

Submission status: Accepted

Solution code:
H = int(input())

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

print(rec(H))

Submission status: Accepted

Solution code:
def at_cal(hp, count):
	if hp > 1:
		count += 1
		hp //= 2
		count *= 2
		return at_cal(hp, count)
	else:
		return count + 1

hp = int(input())
print(at_cal(hp, 0))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    H = I()
    div_cnt = 0
    ans = 0
    while H > 0:
        ans += (1 << div_cnt)
        H = H // 2
        div_cnt += 1
    print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
def f(x):
  if x == 1:
    return 1
  else:
    return 2*f(math.floor(x/2))+1

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

Submission status: Accepted

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

while h>=1:

    h=h/2
    s= s + 2**n
    n+=1
    
    #print(n,h,s)
print(s)

Submission status: Accepted

Solution code:
line=input()
line=line.split()
num=float(line[0])
num2=1
count=1
if int(line[0])<=1:
    print(1)
else:
    while 1<num:
        num = int(num/2)
        num2*=2
        count+=num2
    print(count)

Submission status: Accepted

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

def count(H):
	count=1
	while True:
		if int(H/2)==0:
			break
		else:
			H=int(H/2)
			count+=1
			continue
	return count

A=0
for i in range(int(count(H))):
	A+=2**i
			
print(A)

Submission status: Accepted

Solution code:
import math

def sn(n):
    return pow(2, n+1) - 1

h = int(input())

cnt = 0

if(h==1):
    print(1)
else:
    lim = int(math.log2(h))
    print(sn(lim))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

H=int(input())

count=f(H)
print(count)

Submission status: Accepted

Solution code:
H = int(input())


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

print(f(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
hp = int(input())

count  = 0

while hp > 0:
  count += 1
  if hp == 1:
    hp -= 1
  else:
    hp = hp // 2
    
a = 2 ** count -1
print(a)

Submission status: Accepted

Solution code:
def calc_count(n):
    if n == 1:
        return 1

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


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

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())

ans = 0
i = 1
while True:
    H = H // 2
    ans += i
    i *= 2

    if H == 0:
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

while hp > 0:
    cnt += 1
    if hp == 1:
        hp -= 1
    else:
        hp //= 2

print(2**cnt -1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
dig=len(format(h, 'b'))
print(2**dig-1)

Submission status: Accepted

Solution code:
import math
import sys
h = int(sys.stdin.readline().rstrip())
k = math.floor(math.log2(h))
print(2 ** (k + 1) - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

h = int(input())
n = int(math.log(h, 2))
print(int((1-2**(n+1))/(1-2)))

Submission status: Accepted

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

if H == 1:
    print(1)
else:
    while H != 1:
        H = int(H/2)
        count += 1

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

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

Solution code:
import math
import fractions

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

Submission status: Accepted

Solution code:
h = int(input())
h = str(format(h, 'b'))
print(2**len(h)-1)

Submission status: Accepted

Solution code:
H = input().split()
H = int(H[0])

answer = 0
hp = 1
while hp <= H:
    answer = answer * 2 + 1
    hp *= 2
else:
    print(answer)

Submission status: Accepted

Solution code:
def main(h):
    if h == 1:
        return 1
    else:
        s = h//2
        return main(s)*2

if __name__ == "__main__":
    h = int(input())
    print(main(h)*2-1)

Submission status: Accepted

Solution code:

n = int(input())
if(n == 0):
    printf("0\n");
else:
    attacks = 1;
    moves = 0;
    while(n > 0):
        moves += attacks;
        attacks = attacks << 1;
        n = n >> 1;
    print(moves)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n = int(input())
print((2 ** (int(math.log(n, 2)) + 1) - 1))

Submission status: Accepted

Solution code:
import math

H = float(input())
count = 1
i = 1

while True:
    H = math.floor(H/2)

    if H==0:
        break
    else:
        count = count + 2**i

    i += 1

print(count)

Submission status: Accepted

Solution code:
h = int(input())

count = 0
p = 0

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

print(count)

Submission status: Accepted

Solution code:


n=int(input())
cnt=0
while n:
    cnt+=1
    n=n//2 
print(pow(2,cnt)-1)

Submission status: Accepted

Solution code:
H = int(input())

ans = 1
while H > 0:
    if H == 1:
        ans *= 2
        print(ans-1)
        break
    else:
        H //= 2
        ans *= 2

Submission status: Accepted

Solution code:
def main():
    h  = int(input())
    sum = 0
    tmp = 1
    while(h!=0):
        sum += tmp
        tmp *= 2
        h = h//2
    print(sum)
    return 

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
import sys

total = 0 

dicts = {}
dicts[1] = 1 
dicts[2] = 3 
dicts[0] = 0 
if n == 1:
    print(1)
    sys.exit()

if n == 2:
    print(3)
    sys.exit()
 
def dfs(jk):  
    global total
    global dicts
    if jk in dicts:
        return dicts[jk]
    
    if jk not in dicts:
        half = int(jk //2 )
        new = dfs(half) + dfs(half) + 1
        dicts[jk] = new 
        return new 
    
dfs(n)
#print(dicts)
print(dicts[n])

Submission status: Accepted

Solution code:
#coding:utf-8
H = int(input())
for i in range(41):
    if (2**i-1 >= H):
        print (2**i-1)
        break

Submission status: Accepted

Solution code:
import numpy as np

H = int(input())
cnt = 0
while H != 0:
  H //= 2
  cnt += 1
#cntはモンスターを一体消すのにかかった回数
ans = 2 ** cnt - 1
print(ans)

Submission status: Accepted

Solution code:
import math

monster_hp = int(input())
attack_count = 0

def attack_count_calc(monster_hp):
    if monster_hp == 1:                
        return attack_count + 1
    return attack_count + (2 * attack_count_calc(monster_hp//2) + 1)

print(attack_count_calc(monster_hp))

Submission status: Accepted

Solution code:
#coding:utf-8
H = int(input())
for i in range(50):
    if (2**i-1 >= H):
        print (2**i-1)
        break

Submission status: Accepted

Solution code:
h = int(input())
l_goukei = list()
counter = 0
while(sum(l_goukei) < h):
    if len(l_goukei) == 0:
        l_goukei.append(1)
    else:
        l_goukei.append(l_goukei[-1] * 2)
print(sum(l_goukei))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=int(input())
ANS=0
if S <= 1:
  print(1)
else:
  ANS=1
  while 2**ANS <= S:
    ANS += 1
  #print(ANS**2)
  print(2**ANS-1)

Submission status: Accepted

Solution code:
S=int(input())
ANS=0
if S <= 1:
  print(1)
else:
  ANS=1
  while 2**ANS <= S:
    ANS += 1
  #print(ANS**2)
  print(2**ANS-1)

Submission status: Accepted

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

Submission status: Accepted

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


#5(1)
#2(1) 2(1)
#1(1) 1(1) 1(1) 1(1)
def count(H:int):
    if H == 1:
        return 1
    else:
        return 2 * count(H // 2) + 1

def solve(H: int):
    print(count(H))


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

print(2**count - 1)

Submission status: Accepted

Solution code:
import math

integrationEnemy = int(input())
sqrtCount = 0
harf = 10

while True:
    if harf == 1:
        sqrtCount += 1
        break
    elif harf == 0:
        break
    else:
        sqrtCount += 1

    if sqrtCount == 1:
        harf = math.floor(integrationEnemy / 2)
    else:
        harf = math.floor(harf / 2)

print(2**(sqrtCount)- 1)

Submission status: Accepted

Solution code:
h = int(input())

h_bin = bin(h)
l_bin = len(h_bin)

print(2**(l_bin-2) - 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())

count = 0
while True:
    if a < 2:
        break
    else:
        count += 1
        a = a/2
ans = 2**(count+1)-1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
def bisec(i):
    if i == 1:
        return 1
    else:
        return 2*bisec(i//2)
print(bisec(h)*2-1)

Submission status: Accepted

Solution code:
H = int(input())

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

print(sum)

Submission status: Accepted

Solution code:
H = int(input())
A = []
A.append((H, 1))
ans = 0
while len(A) > 0:
    h, c = A[0]
    A.pop(0)
    ans += c
    if h != 1:
        A.append((h//2, c*2))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

height = 0
for i in range(10**12):
    if H == 1:
        height = i+1
        break
    H = H//2

print(2**height-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())

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

print(saiki(h))

Submission status: Accepted

Solution code:
def f(n):
	if n in memo:
		return memo[n]
	if n <= 1:
		return n
	memo[n] = 2 * f(n // 2) + 1
	return memo[n]

memo = {}
n = int(input())
print(f(n))

Submission status: Accepted

Solution code:
import math

#[H]（Attack_num: 2**0）
#[floor(H/2), floor(H/2)]（Attack_num: 2**1）
#[floor(H/4), floor(H/4), floor(H/4), floor(H/4)]（Attack_num: 2**2）
#↓
#[floor(H/2**N), floor(H/2**N), ..., floor(H/2**N), floor(H/2**N)]（Attack_num: 2**N）
#
#floor(H/2**N) = 1
#
#flooer(H/2**N) = 1となるNを求める。
#このとき、攻撃の最小回数は2**0+2**1+....+2**N+2**N
#
#ex. H = 10
#[10](攻撃回数2**0)
#↓
#[5, 5](攻撃回数2**1)
#↓
#[2, 2, 2, 2](攻撃回数2**2)
#↓
#[1, 1, 1, 1, 1, 1, 1, 1]（攻撃回数2**3）
#↓
#[0, 0, 0, 0, 0, 0, 0, 0]（攻撃回数2**3）
#↓
#全滅
#
#攻撃回数: 2**0+2**1+2**2+2**3+2**3=23

def calc_rep_num(H):
    H_temp = H
    rep = 0
    while not(H_temp == 1):
        H_temp = math.floor(H_temp/2)
        rep += 1
    return rep

def calc_Attack_num(rep):
    Attack_num = (1-2**(rep))/(1-2)+2**rep
    return int(Attack_num)


    
#H: モンスターの体力
H = int(input())
#rep: 階層
rep = calc_rep_num(H)
#Attack_num: 攻撃回数
Attack_num = calc_Attack_num(rep)

print(Attack_num)

Submission status: Accepted

Solution code:
h = int(input())

n = 0

while h >= 2 ** n:
    n += 1

print(2 ** n - 1)

Submission status: Accepted

Solution code:
h = int(input())

def attack(a):
    if a >1:
        return 2 * attack(a//2) +1
    elif a == 1:
        return 1
print(attack(h))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(h):
    res = 0
    a = 1
    while h > 0:
        res += a
        h //= 2
        a *= 2
    return res

assert solve(2) == 3
assert solve(4) == 7
assert solve(1000000000000) == 1099511627775
h = int(input())
print(solve(h))

Submission status: Accepted

Solution code:
H = int(input())
a = 0
for i in range(0, 10**7):
    if H == 1:
        a = i
        break
    H = H // 2
ans = 0
for i in range(0, a+1):
    ans += 2**i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = []
cur = 1
while cur <= n:
  a.append(cur)
  cur *= 2
print(sum(a))

Submission status: Accepted

Solution code:
import math
H = int(input())
ans = 0
cnt = 0
for i in range(10000000000):
 H = H//2
 if H == 0 :
  cnt = i+1
  break
for i in range(cnt):
 ans = ans + 2**i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

#mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np


def main():
	h=int(input())
	
	cnt=0
	p=1
	while h>0:
		cnt+=p
		h//=2
		p*=2
	
	print(cnt)
	
	
	
	
	

if __name__ == "__main__":
	main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from fractions import math

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

l=[1]
for i in range(s):
  l.append(2*l[-1]+1)
print(l[-1])

Submission status: Accepted

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

def rec(x):
    if x == 1:
        return 1

    return 2 * rec(x // 2) + 1


def main():
    from sys import setrecursionlimit

    setrecursionlimit(10 ** 7)

    n = int(input())
    print(rec(n))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H = int(input())
a_num=0
m_num=1
while H>1:
    H = int(H/2)
    a_num+=m_num
    m_num*=2
a_num+=m_num # 最後に残ったHP1の奴らを倒す
print(a_num)

Submission status: Accepted

Solution code:
inp = list(map(int, input().split()))
H = inp[0]

flag = False
vv = []
vv.append(H)
sum = 0

a = 1
for count in range(1,10000000000000000000000):
    if vv[len(vv)-1] != 1:
        sum += a
        a = a*2
        vv.append(int(vv[len(vv)-1] // 2))
    else:
        sum += a
        break

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  h = int(input())
  count = 0
  while True:
    h //= 2
    count += 1
    if h == 0:
      break
  print(2**count - 1)

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
import math

def getOneAttack(hp):
    if hp <= 1:
        return 1
    remainHp = math.floor(hp/2)
    return 1 + getOneAttack(remainHp) * 2

eneHp = int(input())
count = getOneAttack(eneHp)

print("{}".format(count))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H = INT()

print(2**len("{:b}".format(H))-1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math


def main():
    h = int(input())
    x = 2**int(math.log2(h))
    print(2 * x - 1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H = INT()

print(sum([2**i for i in range(len("{:b}".format(H)))]))

Submission status: Accepted

Solution code:
import math

def main():
    a = int(input())
    print(mama(a,0,0))

def mama(hp,num,sum):
    sum = sum + 2**num
    num = num + 1
    if hp <= 1:
        return sum

    hp = hp//2
    return mama(hp,num,sum)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

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

print(attack(H))

Submission status: Accepted

Solution code:
import sys

def main():

    # sys.stdin = open('input153d.txt')

    h = int(input()
            )
    print(func(h) - 1)

def func(h):
    
    if h < 1:
        return 1
    else:
        return 2 * func(h // 2) 


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache


@lru_cache(maxsize=None)
def alg_memoization_recursion(n):
    if n == 1:
        return 1
    else:
        return alg_memoization_recursion(n // 2) + alg_memoization_recursion(n // 2) + 1


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h = int(input().rstrip('\n'))
    print(alg_memoization_recursion(h))


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def atack(x, count):
    if(x == 1):
        return count+1
    return 2 * atack(x // 2, count) + 1

print(atack(int(input()), 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
s = 1
while H!=0:
    H = divmod(H, 2)[0]
    s *= 2
s = s / 2
p = s - 1
print(int(s + p))

Submission status: Accepted

Solution code:
h = int(input())
 

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

Submission status: Accepted

Solution code:
# coding: utf-8
import numpy as np

H = int(input())
x = int(np.log2(H))
sum=0
for i in range(x+1):
    sum+=pow(2,i)
print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(input())
    def attack(x):
        if x == 1:
            return 1
        else:
            x //= 2
            return 2*attack(x)+1
            
    print(attack(N))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

atk = 0
hp = H
ene = 1

while hp > 1:
    atk += ene
    hp = int(hp / 2)
    ene *= 2

atk += ene

print(atk)

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)

H = int(input())

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

print(f(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())


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


print(f(h))

Submission status: Accepted

Solution code:
# coding: utf-8
import math

#N, K = map(int, input().split())
#H = list(map(int, input().split()))
H = int(input())

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

print (2 ** count - 1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import floor


def f(N):
    if N == 1:
        return 1
    return f(floor(N / 2)) * 2 + 1


def main():
    N = int(input())
    print(f(N))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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


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

Submission status: Accepted

Solution code:
h = int(input())

ans = 0
k = 1
while h:
    ans += k
    k *= 2
    h //= 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
H = int(read())
 
answer = 0
coef = 1
while H:
    answer += coef
    H //= 2
    coef *= 2
 
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
H=int(input())
ans=0
at=1
while(H>0):
    H=math.floor(H/2)
    ans=ans+at
    at=at*2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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


print(rec(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)