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:
H=int(input())
X=0
import math
for i in range(0,H):
  X=X+2**i
  H=math.floor(H/2)
  if H<=1/2:
    break
print(X)

Submission status: Accepted

Solution code:
from math import log2

H = int(input())
n = int(log2(H)) + 1
print(2**n - 1)

Submission status: Accepted

Solution code:
import math
import decimal
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

class Library():
    @staticmethod
    def Swap(a,b):
        return [b,a]

    @staticmethod
    def myRound(a,dig=0): # 四捨五入
        p = 10 ** dig
        return (a * p * 2 + 1) // 2 / p

    @staticmethod
    def Roundup(a,dig=0): # 切り上げ
        if a < 0:
            return int(a)
        else:
            return int(a + 0.9)

    @staticmethod
    def Gcd(a,b): #最大公約数
        if (a<b):
            a,b = Library.Swap(a,b)
        if (b==0):
            return a
        else:
            return Library.Gcd(b,a%b)

    @staticmethod
    def Lcm(a,b): #最小公倍数
        return a//Library.Gcd(a,b)*b

    @staticmethod
    def Divisors(a): # 約数列挙
        divisors = []
        for i in range(1,int(a**0.5)+1):
            if a%i==0:
                divisors.append(i)
                if i!=a//i:
                    divisors.append(a//i)
        divisors.sort()
        return divisors

class Prime():
    # コンストラクタ
    # エラストテネスの篩
    def __init__(self,num):
        self.num = num
        self.sieve = [0] * (self.num + 1)
        self.sieve[0] = -1
        self.sieve[1] = -1
        for i in range(2,self.num + 1):
            if not self.sieve[i]:
                self.sieve[i] = i
                for j in range(i * i,self.num + 1,i):
                    if self.sieve[j]:
                        self.sieve[j] = i
    
    # 素数判定
    def isPrime(self,num = None):
        if num is None:
            num = self.num
        if self.sieve[num] == num:
            return True
        else:
            return False
    
    # 素数列挙
    def PrimeNum(self,num = None):
        if num is None:
            num = self.num
        prime = []
        for i in range(2,num):
            if self.sieve[i] == i:
                prime.append(i)
        return prime
    
    # 素因数分解
    def PrimeFact(self,num = None):
        if num is None:
            num = self.num
        fact = []
        while self.sieve[num] != num:
            fact.append(self.sieve[num])
            num //= self.sieve[num]
        fact.append(num)
        return fact

def main():
    h = int(input())
    ans = 0
    enemy = 1
    while h != 0:
        ans += enemy
        if h == 1:
            h -= 1
        else:
            h //= 2
        enemy *= 2
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
h = int(input())

lhb = len(format(h, "b"))
print(2 ** lhb  - 1)

Submission status: Accepted

Solution code:
import math

def main():
    H = int(input())
    x = math.log2(H)
    if(float.is_integer(x)):
        res = math.pow(2,x+1)-1
    else:
        res = math.pow(2,math.floor(x)+1)-1
    print(int(res))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(2**(count)-1)

Submission status: Accepted

Solution code:
import math
def main():
    H = int(input())
    ans = 0
    
    tmp = int(math.log(H) // math.log(2))

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h = int(input())

count = 0
result = 1

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

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

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
j = True
b = 2
c = 0
while j:
    if b > N:
        break
    else:
        b = 2*b
        c = c + 1
    
print(2**(c+1)-1)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
input = sys.stdin.readline
H = int(input())
n = 0
for i in range(10**3):
    if H == 1:
        break
    H //= 2
    n += 1
ans = 1
for i in range(n):
    ans *= 2
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
h=int(input())
an=0
s=1

while 1:
    if h==1:
        print(an+s)
        exit()
    else:
        h=h//2
        an=an+s
        s=s*2

Submission status: Accepted

Solution code:
H = int(input())
myans = 0
mycnt = 0
while H > 0:
    H = H//2
    myans += 2**mycnt
    mycnt += 1
    #print(H, myans)
print(myans)

Submission status: Accepted

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

attack = 0
enemy_num = 1
while H > 0:
    H = H//2
    attack += enemy_num
    enemy_num *= 2
print(attack)

Submission status: Accepted

Solution code:
H = int(input())

if H == 1:
  print("1")
  quit()

bin_h = str(bin(H)[2:])
len_h = len(bin_h)
ans = 2 ** len_h - 1

if bin_h[1] == 1:
  ans += 2 ** (len_h - 1)
  
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

monster = 1
count = 0
while H:
    H //= 2
    count += monster
    monster *= 2

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
H = int(input())
tmp = math.log2(H)
tmp2 = math.floor(tmp + 1)
result = int(2.0 ** tmp2 - 1)
print(result)

Submission status: Accepted

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

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

H=int(input())
print(recur(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
count = 1
if h == 1:
    print(count)
else:
    for i in range(10**(12)):
        h = int(h/2)
        count += 1
        if h == 1:
            break
    print(2**(count)-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
ma = 0
ct = 0
while(n):
    if(n%2==1):
        ma =ct
    n = n//2
    ct+=1
print(2**(ma+1)-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

count = 0
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())
bh=len(str(bin(H)))-2
print(2**bh-1)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H = int(read())

dicts = {}
cnt = 0
que = [H]
dicts[1] = 1

while len(que) != 0:
    acc = que.pop()
    if acc in dicts:
        cnt += dicts[acc]
    elif acc // 2 in dicts:
        dicts[acc] = dicts[acc // 2] * 2 + 1
        cnt += dicts[acc]
    else:
        que.append(acc // 2)
        que.append(acc // 2)
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:


H = int(input())


cnt = 0
while H != 1:
  cnt += 1
  H //= 2

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

print(ans)

Submission status: Accepted

Solution code:
def attack(h, n, total):
    if h == 1:
        return total + n
    else:
        return attack(h // 2, n * 2, total + n)

h = int(input())
print(attack(h, 1, 0))

Submission status: Accepted

Solution code:
n = int(input())
k = 0
while(n>0):
    k+=1;
    n>>=1;
print((1<<k)-1)

Submission status: Accepted

Solution code:
H = int(input())
cnt = 0
num = 1
flag = True
while flag:
    H = H // 2
    cnt += num
    if H == 0:
        flag = False
    else:
        num = num * 2
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

H = int(input())

count = 0
index = 0
while 1:
    H = H //2
    if H==0:
        count = count + 2**index
        print(count)
        sys.exit()
    count = count + 2**index
    index = index + 1

Submission status: Accepted

Solution code:
H = int(input())
k = 0
while True:
    if pow(2,k) <= H < pow(2,k+1):
        break
    k += 1
print(pow(2,k+1)-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans+(2**count))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
H = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
h = int(input())

n = 0
while 2**n <= h:
    n += 1

print(2**n-1)

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

H = INT()

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

Submission status: Accepted

Solution code:
H = int(input())

c = 0
while H > 0:
    H >>= 1
    c += 1

print(2**c-1)

Submission status: Accepted

Solution code:
h=int(input())
l=[]
x=h
ans=0
while x>0:
    l.append(x)
    x//=2
for i in range(len(l)):
    ans+=pow(2,i)

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0
attack_cnt = 0
mon_cnt = 1

while H != 1:
    H = H // 2
    mon_cnt *= 2

    cnt += 1
    attack_cnt += 2 ** (cnt - 1)


print(attack_cnt + mon_cnt)

Submission status: Accepted

Solution code:
import math
x=int(input())
k=0
s=1
while x>=1:
    x//=2
    k+=s
    s*=2
    
print(k)

Submission status: Accepted

Solution code:
H = int(input())

ans = 0
cnt = 0
while 0 != H:
    H = H // 2
    ans += 2**cnt
    cnt += 1

print(ans)

Submission status: Accepted

Solution code:
h = int(input())

hit = 0
n = 0
while True:
  hit += 2**n
  if hit >= h:
    break
  n += 1

print(hit)

Submission status: Accepted

Solution code:
H = int(input())

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

print(cnt)

Submission status: Accepted

Solution code:
h = int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

from math import log

def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())

def bin_pow(a,b):
    result = 1
    while b>0:
        if b&1:
            result*=a
        b>>=1
        a*=a
    return result

n = int(input())
print(bin_pow(2, int(log(n, 2))+1)-1)

Submission status: Accepted

Solution code:
h=int(input())
c=1
while h!=1:
	h = h//2
	c+=1
	#print(h,c)
print(2**c-1)

Submission status: Accepted

Solution code:
import math

H = int(input())
n = int(math.log2(H))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import lru_cache

def resolve():
    import sys
    input = sys.stdin.readline
    
    H = int(input())

    @lru_cache(maxsize=None)
    def dfs(h):
        if h <= 1:
            return 1
        else:
            return dfs(h//2) + dfs(h//2) + 1

    print(dfs(H))


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    monster = H
    c = 0
    while monster > 0:
        c += 1
        if monster < 1:
            monster = 0
        else:
            monster = monster // 2
    ans = 0
    for i in range(c):
        ans += 2 ** i
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H = int(input())

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

print(rec(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

N = 1
while 1:
    if H < N:
        print(N-1)
        sys.exit()
    N *= 2

Submission status: Accepted

Solution code:
h = int(input())
cnt = 0
rest = h % 2
start = h
while h > 1:
    h //= 2
    cnt += 1

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

Submission status: Accepted

Solution code:
h = int(input())

cnt = 1
ans = 0
while cnt <= h:
    ans += cnt
    cnt *= 2

print(ans)

Submission status: Accepted

Solution code:
h = int(input())

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

    print(cnt)

Submission status: Accepted

Solution code:
H = int(input())
for i in range(60):
    if 2 ** i > H:
        print(2 ** i - 1)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

h = int(input())

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

print(count(h))

Submission status: Accepted

Solution code:
H = int(input())
a = 0
cnt = 0

while a == 0:
  if H < 2**cnt:
    a = 1
  else:
    cnt += 1

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

Submission status: Accepted

Solution code:
h = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
i = 0
while 2 ** i < h:
    i += 1
print(2 ** i - 1 if 2 ** i != h else 2 ** (i + 1) - 1)

Submission status: Accepted

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

#整数値入力 1文字の入力
def input_one_number():
    return int(input())


givenH = input_one_number()
cnt = 0
while givenH > 0:
    cnt *= 2
    cnt += 1
    givenH //= 2

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())

for i in range(50):
    if n<2**i:
        break
#print(i)

out=0
for k in range(i):
    out+=2**k

print(out)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=input()
keta=len(bin(N))-2
print 2**keta-1

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

now_H = H
counter = 0
for i in range(H):
    if now_H == 1:
        break
    
    counter += 1
    now_H = now_H // 2

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from itertools import permutations, combinations
from fractions import gcd
from collections import Counter
from math import sqrt
import sys
input = sys.stdin.readline
def lcm(x, y):
    return (x*y//gcd(x, y))
def small_letters():
    return [chr(i) for i in range(97, 97+26)]
def capital_letters():
    return [chr(i) for i in range(65, 65+26)]
def continual_letters(list_x):
    """example"""
    """[2,2,2,2,4,4,5,5,5,8,8,8,8,8] => [4,2,3,5]"""
    i,j = 0,0
    result = []
    k = len(list_x) - 1
    while(True):
        A = list_x[i]
        while(True):
            print(j)
            if list_x[j] != A:
                break
            if j >= k:
                break
            j += 1
        result.append(j-i)
        if i >= k:
            break
        i = j
    result[-1] += 1
    return result


def main():
    """ここに書いてね"""
    H = int(input())
    n = 0
    while(True):
        if H == 0:
            break
        H = H // 2
        n += 1
    print(2**n-1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    H = int(input())
    div = {2**i for i in range(40)}
    ans = 0
    from math import log2, ceil
    if not(H in div):
        for h in range(int(log2(H)) + 1):
            ans += 2**h
        print(ans)
    else:
        for h in range(int(log2(H)) + 1):
            ans += 2**h
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = [list(map(int, s.split())) for s in open(0)][0][0]
cnt = 0 
num_mon = 1
while True:
    if s > 1:
        cnt += num_mon
        s = s // 2
        num_mon += num_mon * 2 - num_mon
    else:
        break 
print(cnt + num_mon)

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def f(x):
    if x==1:
        return 1
    elif x%2 == 0:
        return 1+2*f(x//2)
    else:
        return 1+2*f((x-1)//2)

h = inn()
print(f(h))

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0

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

# print(cnt)

print(2**cnt-1)

Submission status: Accepted

Solution code:
h = int(input())

cnt = 0
while h != 1:
    h = h//2
    cnt += 1
ans = 0
for i in range(1, cnt+1):
    ans += 2**i
print(ans+1)

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

Solution code:
h = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
from collections import deque
h=int(input())
q=deque()
count=0
q.append(h)
while(len(q)>0):
    hi=q.popleft()
    if(hi==1):
        pass
    else:
        attacked_hi=hi//2
        q.append(attacked_hi)
    count+=1

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import sys
H = int(input())
i = 0
s = 1
while 1:
    if H <= 1:
        print(s)
        sys.exit()
    else :
        H //= 2
        i += 1
        s += (2 ** i)

Submission status: Accepted

Solution code:
from math import floor

h = int(input())
p = 0
c = 1

while h > 0:
    h=floor(h/2)
    p,c = p+c,c*2

print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left
from itertools import groupby, permutations, combinations
from fractions import gcd
import numpy as np
from sys import stdin, stderr


def lcm(x, y):
    return (x * y) // gcd(x, y)


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


def main():
    H = int(input())
    return cnt(H)


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

Submission status: Accepted

Solution code:
import math
import sys
h = int(input())
ans = 0
num = 0
if h == 1:
    print(1)
    sys.exit()
for i in range(41,0,-1):
    if 2**i <= h:
        num = 2**i
        rep = i
        # print(i)
        break
for i in range(rep+1):
    ans += 2**i
# print(num)
print(ans)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

H = int(input())
"""
100
50 50
25 25 25 25
12 * 8
6 * 16
3 * 32
1 * 64
ans = 1 + 2 + 4 + 8 + 16 + 32 + 64
"""
x = 1
for i in range(41):
    x *= 2
    if H < x:
        k = i
        break

anss = [1]
for i in range(41):
    anss.append(anss[-1] * 2 + 1)
print(anss[k])

Submission status: Accepted

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

    if h == 0:
        break


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())

bin_str = format(h, 'b')
keta=len(bin_str)

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

Submission status: Accepted

Solution code:
import math

H = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
result = 0
count = 0
while True:
    if H < 1:
        break
    result += pow(2, count)
    H //= 2
    count += 1

print(result)

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 math
H = int(input())
ctr = 1
while H != 1:
	H //= 2
	ctr += 1
	
print(2 ** ctr - 1)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    H = INT()
    s = "{:b}".format(H)
    print(int(s[0] * len(s), 2))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
H = int(input())

ans = 0
cnt = 1
while H > 0:
  ans += cnt
  H = H >> 1
  cnt = cnt << 1
  
print(ans)

Submission status: Accepted

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

memo = dict()


def dfs(v):
    if v == 1:
        return 1
    elif v in memo:
        return memo[v]
    else:
        memo[v] = 2 * dfs(v // 2) + 1
        return memo[v]


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

    print(dfs(H))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import log2

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

    n = int(log2(H))

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    h=I()
    def nextPowerOf2(n): 
        p = 1
        if (n and not(n & (n - 1))):
            return n
        while (p < n) :
            p <<= 1
        return p
    if h==1:
        print(1)
    else:
        p = nextPowerOf2(h)
        if h==p:
            print(nextPowerOf2(h+1)-1)
        else:
            print(p-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Keyence 2020 A
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
import math
h=ni()
t=int(math.log2(h))
# print(t)
# print(2**t)
ans=0
for i in range(t+1):
    ans+=2**i
print(ans)

Submission status: Accepted

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

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

result = attack(h)
print(result)

Submission status: Accepted

Solution code:
H= int(input()) # 数字を変数に格納

attack = 0
count = 1
HP = H

while HP != 1:
    attack += count
    count = count * 2
    HP = int(HP / 2)

attack = attack + count
print(attack)

Submission status: Accepted

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

h = int(input())

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

Submission status: Accepted

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

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:
n=int(input())
a=0
b=0
while(n>0):
    a+=2**b
    n=n//2
    b=b+1
print(a)

Submission status: Accepted

Solution code:
H = int(input())

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

print(solve(H))

Submission status: Accepted

Solution code:
#Hが2のn乗で挟まれるかを考える
#2^n <= H <= 2^(n+1)
H = int(input())
#10^12 = 2^12 * 5^12 < 2^12 * 8*12 = 2*48
for i in range(49):
    if 2**i <= H and H<2**(i+1):
        n = i
        break

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

Submission status: Accepted

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

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

# print('-----output-----')
print(ans)

Submission status: Accepted

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

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

print(attack(h))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def d_caracal_vs_monster():
    H = int(input())
    exp = len(bin(H)) - 2
    return 2**exp - 1

print(d_caracal_vs_monster())