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 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:
import math
from functools import lru_cache

H = int(input())

@lru_cache()
def atack(monster):
  if monster == 1:
    return 1
  else:
    spawn = math.floor(monster / 2)
    return atack(spawn) + atack(spawn) + 1
  
print(atack(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# D - Caracal vs Monster
def main():
    H = int(input())
    print((1 << H.bit_length()) - 1)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


n = int(math.log(H, 2))
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# D - Caracal vs Monster
def main():
    H = int(input())
    cnt, p = 0, 0
    while H:
        H >>= 1
        cnt += 1 << p
        p += 1
    print(cnt)


if __name__ == "__main__":
    main()

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

ans = 1
if H > 1:
    prev, curr = 1, 2
    while 2**curr <= H:
        prev = curr
        curr = curr + 1

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

print(ans)

Submission status: Accepted

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

H = int(input())
print(red(H))

Submission status: Accepted

Solution code:
h = int(input())


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

print(f(h))

Submission status: Accepted

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

Submission status: Accepted

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

while h != 1:
    h=h//2
    kaisuu += 1
    
print(str(2**(kaisuu+1)-1))

Submission status: Accepted

Solution code:
from sys import stdin

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

h = int(stdin.readline())
print(f(h))

Submission status: Accepted

Solution code:
H = int(input())
k = 1
for i in range(1000000):
    if H != 1:
        H = H//2
        k = k + 1
    else:
        break
print(2**k - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

print(f(H))

Submission status: Accepted

Solution code:
h = int(input())

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

print(2**cnt - 1)

Submission status: Accepted

Solution code:
H = int(input())
if H==1:
    print(1)
else:
    for i in range(1, 50):
        if 2**i <= H < 2**(i+1):
            print(2**(i+1)-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def saiki(N):
  if N==1:
    return 1
  a=saiki(N//2)*2+1
  return a
N =int(input())
print(saiki(N))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def propare():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))

    solve(H)

def solve(H: int):
    count = 0
    while 0 < H:
        H = H // 2
        count = count + 1

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

    print(answer)

    return
 
if __name__ == "__main__":
    propare()

Submission status: Accepted

Solution code:
f = lambda x: 2*f(x//2)+1 if x>1 else 1
print(f(int(input())))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
'''input
1000000000000
'''
from sys import stdin
input = stdin.readline
import math


# main starts
h = int(input().strip())
k = math.floor(math.log(h, 2))
print(2 ** (k + 1) - 1)

Submission status: Accepted

Solution code:
def main():
    H = int(input())
    ans = 0
    x = 1
    while H > 0:
        ans += x
        H = H >> 1
        x = x << 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000)


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


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

    res = f(H)

    print(res)



main()

Submission status: Accepted

Solution code:
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:
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
# my functions here!
def pin(type=int):
    return map(type,input().split())
#input
H,=pin()
#solution 
def crcl(num):
    if num == 1:
        return 1
        #print(0)
    else:
        #print(num)
        return 1+crcl(num//2)*2
#print(ans)
print(crcl(H))

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:
# -*- coding:utf-8 -*-

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
H=int(input())

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

Submission status: Accepted

Solution code:
H = int(input())

ret = 0
mon = 1
while H:
    H >>= 1
    ret += mon
    mon <<= 1
print(ret)

# 1bit右シフトすると攻撃後の体力になっている
# 1011 -> 101 -> 10 -> 1 -> 0

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)


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


print(a(int(input())))

Submission status: Accepted

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

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:
import math
N = int(input())
print((2**(math.floor(math.log2(N))+1)-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

con = 0
t = 0

while H > 0:
  H = H // 2
  con += 2 ** (t)
  t += 1
  
print(con)

Submission status: Accepted

Solution code:
from math import log

h=int(input())
a=int(log(h,2))
print(pow(2,a+1)-1)

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache
sys.setrecursionlimit(1000000)


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


print(a(int(input())))

Submission status: Accepted

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

ans+=n
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
ans = 1
n = int(input())

while (ans <= n):
    ans *= 2
print(ans-1)

Submission status: Accepted

Solution code:
import math


H = int(input())

def attacks(health):
    if health == 1:
        return 1
    
    return 1 + 2 * attacks(health//2)

print(attacks(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

ret = 0
mon = 1
while H:
    H //= 2
    ret += mon
    mon <<= 1
print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

print(F(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math 
 
h=int(input())
x =math.floor(math.log(h,2))
print( sum([2**y for y in range(x+1)]))

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    H = int(input())
    ans = 0
    from math import log2
    for h in range(int(log2(H)) + 1):
        ans += 2**h
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())

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

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

Submission status: Accepted

Solution code:
class Main:
    import math
    H = int(input())
    num = 0
    if H == 1:
        num = 1
    else:
        cnt = int(math.log(H, 2))
        for i in range(cnt+1):
            num += 2 ** i
    print(num)

Submission status: Accepted

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

if H == 1:
    ans == 'NA'
else:
    for i in range(100000000000):
        cnt = cnt//2
        B.append(cnt)
        if cnt == 1:
            break

C =[1]
for i in range(1,1001):
    C.append(C[i-1]*2)

if ans == 'NA':
    print('0')
else:
    for i in range(len(B)):
        ans +=C[i]
print(ans)

Submission status: Accepted

Solution code:
h = int(input())
mem = [0] * 100
cnt = 0
 
def atk(k):
    if k == 1:
        mem[1] = 1
        return 1
    else:
        j = int(k // 2)
        l = 0
        while k / ( 2 ** l) >1:
            l += 1
 
        if mem[l] == 0:
            mem[l] = atk(j) * 2 + 1
            return mem[l]
        else:        
            return mem[l]

atk(h)
mem.sort(reverse = True)
print(mem[0])

Submission status: Accepted

Solution code:


h = int(input())
count = 0
enemy = 1
while True:
    if h == 1:
        count += enemy
        break
    else:
        count += enemy
        h = int(h / 2)
        enemy *= 2
print(count)

Submission status: Accepted

Solution code:
H=int(input())
a,b,c=0,0,0
while H>0:
  H=H//2
  a=a+1
  b=2**(a-1)
  c=c+b
  #print(H,a,b,c)
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

result = 2 ** i - 1

print(result)

Submission status: Accepted

Solution code:

def main():
    import math

    H = int(input())
    if H == 1:
        print(1)
    else:
        count = int(math.log(H, 2))
        ans = 0
        for i in range(count+1):
            ans += 2 ** (i)
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h = int(input())

n = h.bit_length()

print(2 ** n - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int( input() )

i = 0
while True:
    if ( 2**i <= h) and ( h < 2**( i + 1 ) ):
        break
    i += 1
print( 2**( i + 1) - 1)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 26 21:17:50 2020

@author: H_Hoshigi
"""

H = int(input())

total_attack = 0

now_H = H
now_N = 1
while now_H > 1:
    total_attack += now_N
    now_H = now_H // 2
    now_N = now_N * 2
total_attack += now_N

print(total_attack)

Submission status: Accepted

Solution code:
def main():
    import math
    H = int(input())
    ans = 0
    for i in range(int(math.log(H,2))+1):
        ans += 2**(i)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h = int(input())
#桁数と1が立っている数程度
def solve(x):
    if x==1:
        return 1
    if x ==0:
        return 0
    
    return 2*solve(x//2)+1
    
print(solve(h))

Submission status: Accepted

Solution code:
def main():
    import math
    H = int(input())
    if H == 1:
        print(1)
    else:
        count = int(math.log(H,2))
        ans = 0
        for i in range(count+1):
            ans += 2**(i)
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

h = int(input())

def sum(list,k):#最初からk個までの和
    s = 0
    for i in range(len(list)-k):
        s = s+ list[i]
    return s

x = math.ceil(math.log2((h+1)*1.0))


print(2**x - 1)

Submission status: Accepted

Solution code:
import sys
H = int(input())
cnt,n = 0,1
while(H!=0):
    H = int(H/2)
    cnt += n
    n = n * 2
print(cnt)
def input():
    return sys.stdin.readline()[:-1]

Submission status: Accepted

Solution code:
h_ = int(input())
h = h_
ans = 0
count = 1
for i in range(h):
  if h <= 1:
    break
  count += 1
  h = h//2

print((2 ** count)-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

h = int(input())

x = int(math.log2(h))
res = 2**(x+1)-1

print(res)

Submission status: Accepted

Solution code:
def d_caracal_vs_monster():
    return 2**int(input()).bit_length() - 1

print(d_caracal_vs_monster())

Submission status: Accepted

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

print(answer)

Submission status: Accepted

Solution code:
def f(x):
	if(x==0):
		return 0
	if(x==1):
		return 1
	return 1 + 2*f(x//2)
  
print(f(int(input())))

Submission status: Accepted

Solution code:
#D
import math
i = int(input())
low = 0
high = 45
for _ in range(100):
    l = 2**low
    h = 2**high
    m = 2**((low+high)/2)
    if i < m:
        high = (low+high)/2
    else:
        low = (low+high)/2
#print(low,high)
tmp = math.floor(high) + 1
print((2**tmp)-1)

Submission status: Accepted

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


h = int(input())
print(findans(h))

Submission status: Accepted

Solution code:
n = int(input())

# i = format(n, 'b')[::-1].find('1')
ans = 0
k = 1
while True:
  n //=2
  ans += k
  k *= 2
  if n == 1:
    print(ans+k)
    break
  elif n < 1:
    print(ans)
    break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(d_caracal_vs_monster())

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0
result = 0


def gener():
  now = 3
  while True:
    yield now
    now = now*2+1


if H == 1:
  print(1)
elif H == 2 or H == 3:
  print(3)
else:
  while True:
    if H <= 1:
      break
    cnt += 1
    H = int(H / 2)

  
  gen = gener()
  gen.__next__()

  for i in range(int(cnt)):
    if i == cnt-2:
      result = gen.__next__()
      print(result)
    else:
      gen.__next__()

Submission status: Accepted

Solution code:
import math
h = int(input())
# cnt = 0
# while h > 0:
#     if h == 1:
#         cnt += 1
#         break
#     else:
#         h //= 2
#         cnt += 1

ans = math.log2(h)
ans = int(ans)
#
# print(2 ** cnt - 1)
print(2 ** (int(ans) + 1) - 1)

Submission status: Accepted

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

else:
  print(H)

Submission status: Accepted

Solution code:
H=int(input())
I=0
J=[1]

if H==1:
    print(1)

else:
    for i in range(1,10**4):
        I=int(H/(2**i))
        J.append(2**i)

        if I==1:
            print(sum(J))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

if H == 1:
  print(1)
else:
  cnt = 1

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

    H = 2 ** (cnt-1)

  cnt = H
  two = H

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

  print(int(cnt+1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
count = 0
total = 0
while(h != 0):
  total = total + pow(2, count)
  h = int(h / 2)
  count = count + 1
print(total)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
input=sys.stdin.readline

h=int(input())
cnt1=1
cnt2=0

while h>1:
    h=h//2
    cnt1*=2
    cnt2 += cnt1//2

print(cnt1+cnt2)

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input().rstrip())
ret = 0
if H == 1:
    ret = 1
elif H in [2, 3]:
    ret = 3
else:
    count = 0
    while H != 1:
        H = H // 2
        count += 1
    ret = 3
    for i in range(count-1):
        ret = 2*ret + 1
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

h=int(input())
if h==1:
  print(1)
  exit(0)
count=0
for i in range(math.floor(math.log(h, 2))+1):
  p=int(math.pow(2, i))
  count+=p
print(count)

Submission status: Accepted

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

ii = 1
ans = 1

while True:
  if H <= 1:
    ans = ans + ii - 1
    break
  else:
    H = H//2
    ii = ii*2
    ans = ans*2
    

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
flag = True
ans = 1
now = n
count = 1


for i in range(10000):
    if n > 2**i:
        pass
    elif n == 1:
        print(1)
        break
    elif n == 2**i:
        print(4*(2**(i)//2)-1)
        break
    else:
        print(4*(2**(i-1)//2)-1)
        break

Submission status: Accepted

Solution code:
import math

h=int(input())
if h==1:
  print(1)
  exit(0)
tmp=math.log(h, 2)
tmp2=math.floor(tmp)
if tmp-tmp2>0:
  h=h//2+1
count=0
for i in range(tmp2+1):
  p=int(math.pow(2, i))
  count+=p
  
print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def f(h):
    return 2 * f(h // 2) + 1 if h else 0
print(f(int(input())))

Submission status: Accepted

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

r = int(math.pow(2,int(math.log(n, 2)) + 1) - 1)
print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())
cnt=0
tmp=[]
ans=1
while(h>1):
  h=h//2
  cnt=cnt+1
  tmp.append(cnt)
for i in tmp:
  ans=2**i
print(ans*2-1)

Submission status: Accepted

Solution code:
from bisect import bisect_right
 
n=int(input())
lst=[1]
lst2=[1]
for i in range(1,41):
  lst.append(2**i)
  lst2.append(lst2[i-1]+lst[i])
  
ind=bisect_right(lst,n)
print(lst2[ind-1])

Submission status: Accepted

Solution code:
H=int(input())
I=0
J=[1]

if H==1:
    print(1)

else:
    for i in range(1,10**4):
        I=int(H/(2**i))
        J.append(2**i)

        if I<=1:
            print(sum(J))
            break

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:
H = int(input())
count = 0
n = 0

if H == 1:
    print(1)
else:
    while H > 0:
        H = int(H/2)
        count += 2**(n)
        n += 1
    
    print(count)

Submission status: Accepted

Solution code:
h = int(input())
n = 1
while(h!=1):
    h=h//2
    n=n+1
total=0
for i in range(n):
    total+=2**i
print(total)

Submission status: Accepted

Solution code:
def main():
    H = int(input())
    n = 1
    ans = 0
    a = 1
    while H != 1:
        H = H // 2
        n += 1
    print(2 ** n - 1)
main()

Submission status: Accepted

Solution code:
"""
if a monster is not attacked, it doesn't do anything, so we can
deal with each living monster as a separate problem that takes
a certain number of moves to kill it and all of its offspring.
when x is not 1,
num(x) = 2*num(floor(x/2))+1
(because it took one move to kill it, and there will be two offspring)
and when x is 2 or 3,
num(x) = 3
so we can do some recursion, or memoization, or tabulation
"""

from math import floor


def get_num_attacks(H):
  if H>3:
    return 2*get_num_attacks(floor(H/2))+1
  if H==2 or H==3:
    return 3
  if H==1:
    return 1


if __name__ == "__main__":
  H = int(input())
  print(get_num_attacks(H))

Submission status: Accepted

Solution code:
#H<=10**12より H<=2**40
H=int(input())
import math
keisuu=[]
i=39

while i>=1:
  if H >= 2**i:
    H -= 2**i
    keisuu.append(1)
  else:
    keisuu.append(0)
  i -=1
  
if H==1:
  keisuu.append(1)
else:
  keisuu.append(0)
  
while keisuu[0]==0:
  keisuu.pop(0)
  
keisuu.reverse()
#print(keisuu)
a=len(keisuu)

if a>=2:
  ans=(2**a)-1
  print(ans)
else:
  print(1)

#ans=0
#print(ans,keisuu)
#while len(keisuu)>1:
#  keisuu[-2] += 2
#  if keisuu[-1]==1:
#    keisuu.pop(-1)
#  else:
#    keisuu[-1] -=1
#  ans+=1
  #print(ans,keisuu)
  
#ans+=keisuu[0]
#print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def solve(H: int):

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

    i = 1
    m = 1

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

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

atk = 1

for i in range(100):
    h = h//2
    atk = atk * 2
    if h == 0:
        break


print(atk-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

sum = 0
a = H
fin = 1

if H == 1:
  sum = sum + 1
else :
  while a>=1 :
    a = a/2
    sum = sum + 1
    
for n in range(sum):
  fin = fin *2
print(fin -1)

Submission status: Accepted

Solution code:
h = int(input())

attack = 0
kai = 0

while h//2**kai>=1:
    attack += 2**kai
    kai += 1

print(attack)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
c = 0
while h > 1:
    h = h//2
    c +=1
#    print(h)
c = c + 1
#print(c)
r = 1
re = 1
for _ in range(1,c):
    r *= 2
#    print(r)
    re +=r
print(re)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

print(solve(H, 1))

Submission status: Accepted

Solution code:
import math

H = int(input())

count = 1
while True:
    if H == 1:
        break
    H = math.floor(H/2)
    count += 1

print(2**count-1)

Submission status: Accepted

Solution code:
def f(x):
    if x == 1:
        return 1
    return 2*f(x//2)+1
N = int(input())
print(f(N))

Submission status: Accepted

Solution code:
N=int(input())

def sep_to_1(n):
    sep_mon=n
    count=0
    mons_num=1
    sum_sep_count=0
    while sep_mon!=1:
        count+=1
#         print("stage",count)
        sep_mon=sep_mon//2
        sum_sep_count+=mons_num
        mons_num=2*mons_num
        
#         print("sep_mon",sep_mon)
#         print("mons_num",mons_num)
#         print("sum_sep_count",sum_sep_count)
    return sum_sep_count+mons_num

print(sep_to_1(N))

Submission status: Accepted

Solution code:
h = int(input())

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

attack = 0
for i in range(step):
    attack += 2 ** i

print(attack)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

i = 0
a = 0

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

print(a)

Submission status: Accepted

Solution code:
hp = int(input())
nmons = 1
numatk = 0

while hp != 0:
    if hp == 1:
        numatk += nmons
        hp = 0
    else:
        hp /= 2
        hp = int(hp)
        numatk += nmons
        nmons *= 2

print(numatk)

Submission status: Accepted

Solution code:
h = int(input())

double = 0
for i in range(h, 1, -1):
  if h == 1:
    break
  h = h // 2
  double += 1

total = 0
for i in range(double + 1):
  total += pow(2, i)
print(total)

Submission status: Accepted

Solution code:
H = int(input())
waru = H
cont = 0
while(1):
  if waru<=1:
    break
  waru = int(waru/2)
  cont = cont + 1
  
  
  
kaizyo = []

for i in range(41):
  kaizyo.append(2**i)

print(sum(kaizyo[:cont+1]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()  # 等比数列。こうひ2
n = 0
unchi = int(s)
ans = 0

while unchi > 1:
    unchi = int(unchi) // 2
    # print(unchi)
    n += 1

# for i in range(int(s)):  # 割りまくる
#     unchi = int(s) // 2

# print("")
# print("")
# print(n)
# print("")
# print("")

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

print(ans+1)

Submission status: Accepted

Solution code:
h=int(input())
d=dict()
d[0]=0
d[1]=1
d[2]=3
d[3]=3
def solve(h):
    if h in d.keys():
        return d[h]
    d[h]=2*solve(h//2)+1
    return d[h]
print(solve(h))

Submission status: Accepted

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