Problem:


Score : 400 points

Problem Statement

Caracal is fighting with a monster.

The health of the monster is H.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

If the monster's health is 1, it drops to 0.

If the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \lfloor X/2 \rfloor.

(\lfloor r \rfloor denotes the greatest integer not exceeding r.)

Caracal wins when the healths of all existing monsters become 0 or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

1 \leq H \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H

Output

Find the minimum number of attacks Caracal needs to make before winning.

Sample Input 1

2

Sample Output 1

3

When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of 1.

Then, Caracal can attack each of these new monsters once and win with a total of three attacks.

Sample Input 2

4

Sample Output 2

7

Sample Input 3

1000000000000

Sample Output 3

1099511627775



Sample input:
2


Sample output:
3

Submission status: Accepted

Solution code:
# D
H = int(input())
cnt = 1
ans = 0

while True:
    if 2**cnt > H:
        cnt -= 1
        break
    elif 2**cnt == H:
        break
    else:
        cnt += 1

for c in range(cnt+1):
    ans += 2**c
print(ans)

Submission status: Accepted

Solution code:
import math

h = int(input())
n = math.floor(math.log2(h)) + 1

print(2 ** n - 1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    def solve(n):
        if n == 1:
            return 1
        return solve(n // 2) * 2 + 1

    H = int(input())

    print(solve(H))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    H = int(input())

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

h = int(input())
l = int(math.log(h, 2))
p = (2**l)*2-1
print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
for i in range(0, 10**20 + 1):
  if 2**i <= H < 2 ** (i + 1):
    break
print(2 ** (i + 1) - 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
H=int(input())
c=0
while H!=0:
  c+=1
  H=H//2

print(2**c-1)

Submission status: Accepted

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

Submission status: Accepted

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


def solve(H: int):
    n = 1
    attack = 0
    while H > 1:
        attack += n
        H = H // 2
        n *= 2
    attack += n
    return attack


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    h = I()
    num = 1
    ans = 0
    while h>1:
        h//=2
        ans += num
        num*=2
    ans += num
    print(ans)
main()

Submission status: Accepted

Solution code:
H = int(input())

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

import math as m
n = m.floor(m.log2(H))+1
ans = (2**n) - 1

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)
def rec(n):
    if n == 1: 
        return 1
    return rec(n//2)*2+1

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

Submission status: Accepted

Solution code:
from sys import setrecursionlimit

setrecursionlimit(1000000)

H = int(input())


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


print(f(H))

Submission status: Accepted

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

while (h != 1):
    h = math.floor(h / 2)
    l += 1
ans = 0

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

Submission status: Accepted

Solution code:

def main():
    h = int(input())
    cnt = 0
    while(h>0):
        h //= 2
        cnt += 1
    x = 0
    for i in range(cnt):
        x = x * 2 +1
    print(x)
    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
H = int(input())

ans = 1
if H != 1:
    h = H
    for i in range(1, 40):
        if int(h/2) >= 2:
#            print(i, ans, h, 'a')
            ans += 2**i
            h = int(h/2)
        else:
#            print(i, ans, h, 'b')
            ans += 2**i
            break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# D - Caracal vs Monster
H = int(input())

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

print(rec(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
SUM = 0
cn = 1

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

for i in range(10000):
    H = H // 2
    cn = cn + 1
    if H == 1:
        break

for i in range(cn):
    SUM = SUM + (2**i)
    
print(SUM)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import numpy


H = int(input())

ans = 1
HP = 2
tmp = 1
while True:
    if H < HP:
        break
    else:
        tmp *= 2
        ans += tmp
        HP *= 2


print(ans)

Submission status: Accepted

Solution code:
H = int(input())

def attack(h):
    if h == 1:
        return 0
    r = 2
    h //= 2
    ans = 2
    while h > 1:
        h //= 2
        r *= 2
        ans += r
    return ans
    
    
print(1 + attack(H))

Submission status: Accepted

Solution code:
import sys
H=int(input())
a = 0
while   True:
    H=int(H/2)
    a=a+1
    #print(H) 
    if  H==0:
        print(2**a-1) 
        sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
Ans = 0
n = 0
while True:
    if H != 1:
        H = H//2
        Ans += 2**n
        n += 1
    else:
        Ans += 2**n
        break
print(Ans)

Submission status: Accepted

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

Submission status: Accepted

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

H = int(input())

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

h = int(input())

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

print(f(h))

Submission status: Accepted

Solution code:
#!/usr/bin/env python

h = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

i = 1
cnt = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())
if H==1:
    print(1)
else:
    i=1
    count=1
    while H//2!=1:
        i*=2
        count+=i
        H=H//2
    i*=2
    count+=i
    print(count)

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

H = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

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

Submission status: Accepted

Solution code:
import  math

def pow(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

H = int(input())

#print(int(math.log2(H)))
print(pow(2,int(math.log2(H))+1)-1)

Submission status: Accepted

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

if H == 1:
    print(2**(cnt+1)-1)

else:
    print(2**cnt-1)

Submission status: Accepted

Solution code:
h=int(input())

cnt=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

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

    ans = 0
    n = 1
    for i in range(10**12):
        if H == 1:
            ans += n
            print(ans)
            exit()
        ans += n
        n *= 2
        H = int(H/2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a=int(input())
import math
total=0
total2=1
while True:
    if a>1:
        a=a//2
        total+=total2
        total2=total2*2
    elif a==1:
        print(total+total2)
        break

Submission status: Accepted

Solution code:
H = int(input())

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

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())
count = 1
i = 2
while H > 1:
  H //= 2
  count += i
  i *= 2
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0

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

    if H == 0:
        break

print(2**cnt-1)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    cur = 1
    cnt = 1

    while 2 * cur <= H:
        cur *= 2
        cnt *= 2
        cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

Submission status: Accepted

Solution code:
import math


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

    counter = 0
    multiple = 1

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

    print(counter)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D_fix
# CreatedDate:  2020-08-30 14:54:11 +0900
# LastModified: 2020-08-30 15:07:52 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    H = int(input())
    mul = 0
    while H != 1:
        mul += 1
        H //= 2
    print(2**(mul+1)-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
H = int(input())

import math

def caracal(H):
    if H == 1:
        return 1
    return 2*caracal(math.floor(H/2)) + 1

print(caracal(H))

Submission status: Accepted

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


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

    ans = f(h)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    h = int(input())
    num = 1
    ans = 1

    while True:  # h以上で最小の2の累乗を探す
        num *= 2
        if h < num:
            break
        elif h == num:
            ans = 2 * ans + 1
            break
        ans = 2 * ans + 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

cnt=0
a=copy.copy(h)
while a>1:
    a=math.ceil(a/2)
    cnt+=1

if h==2**(cnt):
    print(2**(cnt+1)+-1)
else:
    print(2**(cnt)+-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

if h == 1:
    ans += n_enemy

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

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

if __name__=='__main__':
    h = I()
    print(solve(h))

Submission status: Accepted

Solution code:
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    l = [1, 2, 4, 8, 16, 
        32, 64, 128, 256, 512,
        1024, 2048, 4096, 8192, 16384, 
        32768, 65536, 131072, 262144, 524288, 
        1048576, 2097152, 4194304, 8388608, 16777216, 
        33554432, 67108864, 134217728, 268435456, 536870912, 
        1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 
        34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 
        1099511627776]
    c = 0
    while l[c]<h and l[c+1]<=h:
        c += 1
    print(2*l[c]-1)
    return

if __name__=='__main__':
    h = I()
    solve()

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# D - Caracal vs Monster
H = int(input())

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

print(rec(H))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
H=int(input())

x=0
while True:
    x+=1
    if 2**x>H:
        x-=1
        break

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
cnt = 1

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

print(cnt - 1)

Submission status: Accepted

Solution code:
import os, sys, re, math

memo = {}
def attack(h):
    result = memo.get(h)
    if result:
        return result

    result = 1
    if h > 1:
        result += attack(h // 2) * 2
    memo[h] = result
    return result

print(attack(int(input())))

Submission status: Accepted

Solution code:
import os, sys, re, math

memo = {}
def attack(h):
    result = memo.get(h)
    if result:
        return result
    if h == 1:
        result = 1
    else:
        result = 1 + attack(h // 2) * 2
    memo[h] = result
    return result

H = int(input())

print(attack(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
H=int(input())

sum = 0
i = 0
while H > 0:
    i += 1
    hits = 2**(i-1)
    sum += hits
    if H == 1:
        H = 0
    else:
        H //= 2

print(sum)

Submission status: Accepted

Solution code:
n=int(input())

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

ans+=1*cnt

print(ans)

Submission status: Accepted

Solution code:
H =int(input())

#h= 1
#while 2**(h+1) <= H:
#    h += 1
#
#n=2**(h+1) - 1
#print(n)
#
import math
def helper(h):
    if h ==1:
        return 1
    return 1 + 2 * helper(math.floor(h/2))
print(helper(H))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n = ini()
ans = 0
tmp = 1
while n > 0:
    n //= 2
    ans += tmp
    tmp *= 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
cnt = -1

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

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

print(ans)

Submission status: Accepted

Solution code:
h = int(input())

power = 0
while True:
  if 2**power <= h < 2**(power+1):
    break
  else:
    power += 1
    
layer = power + 1
ans = int(2**layer) - 1
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math as mt

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

n = int(readline())
cnt = 1
while n != 1:
  n = n//2
  cnt += 1

print(sum(2**i for i in range(cnt)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


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

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

    ans = 2 ** depth - 1
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H = int(input())

pw = 1
cnt = 0
while True:
    pw *= 2
    if pw > H:
        break
    cnt += 1

print(pw - 1)

Submission status: Accepted

Solution code:
H = int(input())
def atk(n):
  if n==1: return 1
  return 1 + 2*(atk(n//2))

print(atk(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    if h == 1:
        minimum = 1
    else:
        if h % 2 == 1:
            h -= 1

        minimum = 0
        power = 0
        while True:
            minimum += 2 ** power
            power += 1

            if 2 ** power > h:
                break

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

tmp=math.log2(h)

print(2**(int(tmp+1))-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
num = {}
lis = [H]

h = H
while h > 1:
    h //= 2
    num[h] = 0
    lis = [h] + lis

num[1] = 1

for n in lis[1:]:
    num[n] = 2*num[n//2] + 1

print(num[H])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import log2

print(2 ** int(log2(int(input())) + 1) - 1)

Submission status: Accepted

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

print(attack(h))

Submission status: Accepted

Solution code:
#D - Caracal vs Monster
H = int(input())

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

print(attack(H))

Submission status: Accepted

Solution code:
from math import floor

H = int(input())

ans = 0
r = H
n = 0
while not (r == 1):
    n += 1
    ans += 2 ** n
    r = floor(r / 2)

ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0
def attack(hp, cnt):
    cnt += 1
    if hp == 1:
        return cnt

    cnt += attack(hp//2, 0) * 2
    return cnt

print(attack(H, cnt))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
H = int(input())

layer = 1
atack_cnt = 1

while True:
    if H == 1:
        print(atack_cnt)
        exit()
    
    elif H > 1:
        H = int(H/2)
        atack_cnt += layer*2
        layer *= 2

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
b = int(1)


if a == 1:
    print("1")
else:
  for i in range(114514):
    a = a // 2
    b = b + 1
    if a == 1:
      break
    else:
      pass
  print(2 ** b - 1)

Submission status: Accepted

Solution code:
import sys

H = int(next(sys.stdin.buffer))

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

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    H = int(input())
    ans = 0
    i = 0
    while(H >= 1):
        ans += 2**i
        H /= 2
        i += 1

    print(ans)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

H = int(input())

print(kougeki(H))

Submission status: Accepted

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


s = attack(int(input()))
print(s)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

h = inp()

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

print(2**cnt-1)

Submission status: Accepted

Solution code:
#再帰関数
#もし残り体力が１なら一回切るだけ
#それ以外では１回(モンスターを一回きる)+2*int(体力//2)回必要
def attack(x):
  if x==1:
    return 1
  else:
    return 2*attack(x//2)+1
h=int(input())
print(attack(h))

Submission status: Accepted

Solution code:
from functools import lru_cache
@lru_cache(maxsize=None)
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:
import math
print(2**int(math.log2(int(input())) + 1) - 1)

Submission status: Accepted

Solution code:
#aのn乗を計算
def pow(a,n):
  if n==0:
    return 1
  else:
    k=pow(a*a,n//2)
    if n%2==1:
      k=k*a
  return k

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

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    H = int(input())
    cnt = 0
    while H!=1:
        H //= 2
        cnt += 1
    
    ans = 0
    for c in range(cnt+1):
        ans += pow(2, c)
    
    print(ans)

Submission status: Accepted

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