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 numpy as np
import math

def solve(h):
  if h == 1:
    return 1

  hh = h // 2
  return 2*solve(hh) + 1


if __name__ == "__main__":
  _h = int(input())
  ans = solve(_h)
  print(ans)

Submission status: Accepted

Solution code:
from collections import deque


def main():
    h = int(input())
    count = 0
    # queue = deque([h])
    # while len(queue) > 0:
    #     mon = queue.popleft()
    #     count += 1
    #     if mon == 1:
    #         continue
    #     else:
    #         new_hp = mon // 2
    #         queue.append(new_hp)
    #         queue.append(new_hp)
    factor = 1
    while h > 1:
        h //= 2
        count += factor
        factor *= 2
    count += factor
    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

H = int(input())
print(Attack(H))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import math
h = int(input())
a = 10000000000000
b = 0
for i in range(40):
    if a > h - pow(2, i) >= 0:
        a = h - pow(2, i)
        b = i

c = 0
for i in range(b+1):
    c += pow(2, i)

print(c)

Submission status: Accepted

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


print(f(h))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0
lst = []
while True:
    cnt += 1
    H = int(H / 2)
    if H <= 0:
        break

ans = 0
for i in range(cnt):

    ans += (2 ** (i))
    #print(i, ans)

print(int(ans))

Submission status: Accepted

Solution code:
N = int(input())

th = 1

while True:
  if N < th*2:
    break
  else:
    th *= 2

print(th*2-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]


h = fetch_int_input()[0]

count = 0
def attack(tmp_h):
    global count
    if tmp_h > 1:
        attack(tmp_h / 2)
        attack(tmp_h / 2)
        count += 1
    else:
        count += 1
        return
import math
while h >= 1:
    h = math.floor(h / 2)
    count += 1

answer = 0
for i in range(count):
    answer += pow(2, i)
print(answer)

Submission status: Accepted

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


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

    # n, k = map(int, input().split())
    # h = list(map(int, input().split()))
    h = int(input())

    print(saiki(h))


main()

Submission status: Accepted

Solution code:
n=int(input())

i=0

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

print(2**(i)-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

count = find_count(H)
print(count)

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
h = int(input())

cnt = 1
n = 1
while True:
    n *= 2
    if n > h:
        print(cnt)
        exit()
    cnt += n

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
h = int(input())
i = 0
count = 0
if h == 1:
    count = 1
else:
    while(True):
        if h % 2 == 0:
            h = h // 2
        else:
            h = h // 2
        count += 2 ** i
        i += 1
        if h == 1:
            break
    count += 2 ** i
print(count)

Submission status: Accepted

Solution code:
H = int(input())

import sys
sys.setrecursionlimit(10**9)
cnt = 0
def f(x):
    global cnt
    if x == 1:
        cnt += 1
        return

    else:
        x //= 2
        cnt += 1

        f(x)

f(H)
ans = 0
for x in range(cnt):
    ans += 2**x


print(ans)

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

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

    now = H
    num = 1
    res = 0

    while True:
        if now == 1:
            res += num
            break
        res += num
        now = now // 2
        num *= 2

    print(res)



main()

Submission status: Accepted

Solution code:
h = int(input())
i = 0
while True:
    if h <= 1:
        break
    h = h // 2
    i += 1

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

Submission status: Accepted

Solution code:
# 2020/01/26
# AtCoder Beginner Contest 153 - D

# Input
h = int(input())

# Calc
wk_h = h
div_cnt = 0
while(wk_h >= 1):
    div_cnt = div_cnt + 1
    wk_h = wk_h // 2

at_cnt = 0
for i in range(div_cnt):
    at_cnt = at_cnt + 2 ** i
    
# Output
print(at_cnt)

Submission status: Accepted

Solution code:
from math import floor
H=int(input())
number=1
a=1
count=0
flag=True
while(flag):
   if H>=2:
      H=floor(H/2)
      number+=a*2
      a*=2
   else:
      flag=False
print(number)

Submission status: Accepted

Solution code:
import math

h = int(input())
t = 1
r = 0
while True:
    r += t
    if h == 1:
        break
    else:
        h = math.floor(h / 2)
        t *= 2
print(r)

Submission status: Accepted

Solution code:
h = int(input())
i = 1
a = 1
b = 1
c = 1

while h >= a:
    a = 2 ** i
    i += 1

s = 0
t = True
for j in range(1, i-1):
    c += 2 ** j

print(c)

Submission status: Accepted

Solution code:
import sys
import math

H =int(sys.stdin.readline())


sqrt = math.sqrt(H)

flag = 0
target = H
keisu = 1
attack = 1
if target == 1:
    print(attack)
else:
    while(flag == 0):
        target = target // 2
        attack += keisu * 2
        keisu = keisu*2
        if target == 1:
            flag = 1
    print(attack)

Submission status: Accepted

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

h = int(input())
print(get_num_of_attack(h))

Submission status: Accepted

Solution code:
import math
H = int(input())
kaisu = int(math.log2(H))+1

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

Submission status: Accepted

Solution code:
import math

H = int(input())

N = int(math.log2(H) + 1)
a = int(math.pow(2, N) - 1)

print(a)

Submission status: Accepted

Solution code:
import sys

def main():
    h = int(input().replace('\n','').split()[0])
    cnt=0
    res=0
    while(h>=1):
        h= h/2
        cnt+=1
    for i in range(cnt):
        res+=2**i
    print(res)
if __name__ == '__main__':
    input = sys.stdin.readline
    main()

Submission status: Accepted

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

H = int(input())
ctr = 0

while True:
    ctr += 1
    if pow(2, ctr) > H:
        break
print((1 - pow(2, ctr)) // (-1))

Submission status: Accepted

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

print(2 ** (math.floor(math.log(H, 2)) + 1) - 1)

Submission status: Accepted

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

H = int(input())
print(ANS(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

if H <= 0:
    print(0)
else:
    result = 1
    tmp = 1
    while H > 1:
        H = H // 2
        tmp *= 2
        result += tmp
    print(result)

Submission status: Accepted

Solution code:
H = int(input())
a = H
b = 0
while a>1:
    b+=1
    a = a //2
    
ans = sum([2**x for x in range(b+1)])
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

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

print(d)

Submission status: Accepted

Solution code:
H = int(input())

idx = len(bin(H)) - 2
ans = 1
for i in range(idx-1):
    ans = 2*ans + 1

print(ans)

Submission status: Accepted

Solution code:
import math
import sys
H = int(input())
#H = list(map(int,input().split()))
#H = sorted(H,reverse=True)

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

mon_num = 1
attack_num = 0
for k in range(1000000000000):
    
    attack_num += mon_num
    
    H = math.floor(H/2)
    mon_num = mon_num*2
    
    
    if H == 1:
        attack_num += mon_num
        break
print(attack_num)

Submission status: Accepted

Solution code:
h = int(input())

depth = 1
count = 0
while True:
    if h == 0:
        break
    h = h//2
    count += 2**(depth-1)
    depth += 1

print(count)

Submission status: Accepted

Solution code:
from math import log2

# print(log2(4))
def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x


a = int(input())
if a ==1:
    print(1)
    exit()
a = int(log2(a))
# print(a)

res = 4*(pow_k(2,a-1))-1
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
H = int( input().strip() ) ;
r = 1; 

c = 0 ;
while True :
	c += r ;
	r *= 2;
	H //= 2;
	if H ==0 : break ;
print ( c ) ;

Submission status: Accepted

Solution code:
H = int(input())
ans = 1
t = 1

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

print(ans)

Submission status: Accepted

Solution code:
h = int(input())

ans = 0
cnt = 0

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

print(ans)

Submission status: Accepted

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

h = int(input())
ans = solve(h)
print(ans)

Submission status: Accepted

Solution code:
import math

H=int(input())

a=math.log(H,2)

n=math.floor(a)

ans=0

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
x = len(bin(H)) - 2
print(sum([2**i for i  in  range(x)]))

Submission status: Accepted

Solution code:
h = int(input())

ans = 0
cnt = 0
for i in range(h):
    if h > 1:
        h = h // 2
        cnt +=1
    else:
        break
val = [1]
for i in range(1,cnt+1):
    val.append(2**i)
print(sum(val))

Submission status: Accepted

Solution code:
import math

H = int(input())

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



curr = 1
tmp = 2
for _ in range(40):
    if tmp <= H < tmp * 2:
        print(2**(curr+1)-1)
        exit()
    else:
        curr += 1
        tmp *= 2

Submission status: Accepted

Solution code:
H = int(input())

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

print(count(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

atack = 0
mon_num = 1

while H!=1:
    atack += mon_num
    H = (H//2)
    mon_num = 2*mon_num
    

atack += mon_num

print(atack)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

h=ii()
num = 1
cnt=0
while h >0:
    if h >1:
        h = floor(h/2)
        cnt+=num
        num*=2
    else:
        h-=1
        cnt+=num

print(cnt)

Submission status: Accepted

Solution code:
h = int(input())
ret = 1
if h != 1:
    for i in range(10**6):
        h = h//2
        if h//2 < 1:
            ret += 1
            break
        else:
            ret += 1
else:
    pass
print(sum([2**i for i in range(ret)]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import numpy as np


DEBUG = True
dprint = print if DEBUG else lambda *x : x

N = int(input().strip())

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


print(f(N))

Submission status: Accepted

Solution code:
h = int(input())
c=1
while(1):
  if 2**c <= h:
      c+=1
  else:
      c-=1
      break

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

Submission status: Accepted

Solution code:
import math

N = int(input())
M = math.floor(math.log2(N))
print(2**(M+1)-1)

Submission status: Accepted

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

### TESTCASE
test = ""
#test = \
"""
2
3
"""

"""
4
7
"""

"""
10
15
"""

"""
1000000000000
1099511627775
"""
############
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
####### MAIN

h = int(input2())

c = 0
while h:
    h //= 2
    c += 1

s = 0
v = 1
while c:
    c -= 1
    s += v
    v *= 2


print(s)

Submission status: Accepted

Solution code:
h =int(input())

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

Submission status: Accepted

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

while a:
    a //= 2
    b += 1

print(2 ** b - 1)

Submission status: Accepted

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

cnt = 0
ans = 1
while True:
    if h == 1:
        break

    h = math.floor(h / 2)
    cnt += 1
    ans += 2 ** cnt
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

count = 1
h = H

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

print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def atack(h):
    if h == 1:
        return 1
    else:
        return 2 * atack(h//2) + 1


h = int(input())
print(atack(h))

Submission status: Accepted

Solution code:
H = int(input())

import numpy as np

x = int(np.log2(H))
print(2 ** (x+1) - 1)

Submission status: Accepted

Solution code:
h = int(input())

now = 1
cnt = 0
while now <= h:
	cnt += now
	now *= 2
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

H = int(input())

memo = {}

def f(n):
  if n <= 1:
    return 1
  if n in memo:
    return memo[n]
  
  memo[n] = 1 + f(math.floor(n / 2.0)) * 2
  return memo[n]

print(f(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())
#H=10**12
#H=9
i=0
s=0
while(H!=1):
    H//=2
    s+=2**i
    i+=1

s+=2**i
print(s)

Submission status: Accepted

Solution code:
H = int(input())
su = 0
ans = 0
if H == 1:
  print(1)
else:
  while not H == 1:
    H //= 2
    su += 1
  for i in range(1,su+1):
    ans += 2**i
  print(ans+1)

Submission status: Accepted

Solution code:
import math


def solve(h):
    depth = 0
    total = 0
    while h > 0:
        if h == 1:
            h = 0
        else:
            h = math.floor(h / 2)

        total += 2**depth
        depth += 1

    return total


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

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

ex = int(math.log2(H)) + 1

print(2 ** ex - 1)

Submission status: Accepted

Solution code:
h = int(input())
d = {}

def caracal(h):
    if h in d.keys():
        return d[h]
    else:
        if h == 1:
            d[h] = 1
            return d[h]
        else:
            d[h] = 2 * caracal(h // 2) + 1
            return d[h]

print(caracal(h))

Submission status: Accepted

Solution code:
h = int(input())

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

print(n+c)

Submission status: Accepted

Solution code:
from math import log2, floor
n = int(input())
b = floor(log2(n)) + 1
print(2**b-1)

Submission status: Accepted

Solution code:
H = int(input())

tmp = 1
counter = 0

while tmp <= H:
    tmp = tmp*2 
    counter += 1

print(tmp - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect
from fractions import Fraction
 
H = int(input())
A = math.log(H, 2)

ans = 0
for i in range(0,int(A)+1):
    ans += 2**i

print(ans)

Submission status: Accepted

Solution code:
import math


def highest_power_of_2(n):
    p = int(math.log(n, 2))
    return p

  
def solve(H):
    power_2 = highest_power_of_2(H)
    ans = 2 * pow(2, power_2) - 1
    print(ans)


def iin(): return int(input())

    
H = iin()
solve(H)

Submission status: Accepted

Solution code:
h = int(input())
def saiki(a):
    step = 0
    if a != 1:
        step += 1
        return  saiki(a//2) * 2 ** step
    else:
        return 1
print(saiki(h*2)-1)

Submission status: Accepted

Solution code:
h=int(input())


t=0
while h!=1:
    # print(h)
    h//=2
    t+=1
    

print(2**t*2-1)

Submission status: Accepted

Solution code:
import math

h = int(input())

total = 0
attack = 1

while(h != 0):
    total += attack
    attack *= 2
    h = int(h/2)

print(total)

Submission status: Accepted

Solution code:
h = int(input())

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

print(solve(h))

Submission status: Accepted

Solution code:
import unittest
import math


class TestD(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(2), 3)

    def test_2(self):
        self.assertEqual(think(4), 7)

    def test_3(self):
        self.assertEqual(think(1000000000000), 1099511627775)


def solve():
    h = read()
    result = think(h)
    write(result)


def read():
    return read_int(1)[0]


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(h):
    rank = math.floor(math.log(h) / math.log(2)) + 1
    return 2 ** rank - 1


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Submission status: Accepted

Solution code:
H=int(input())

s=bin(H)
s=s[2:]
print(2**len(s)-1)

Submission status: Accepted

Solution code:
h = int(input())

ans = 0
i = 0
x = 0
while True:
    x = 2**i
    if x > h:
        break
    ans += x
    i += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import log, floor

H = int(input())

a = 0
for i in range(floor(log(H, 2)) + 1):
    a += 2 ** i
print(a)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    H = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    n = 0
    while (True):
        n += 1
        H = H // 2
        if H == 0:
            break

    print(sum([2**(i - 1) for i in range(1, n + 1)]))


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4"""
        output = """7"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1000000000000"""
        output = """1099511627775"""
        self.assertIO(input, output)

Submission status: Accepted

Solution code:
from math import log2, floor

h = int(input())
tmp = floor(log2(h)) + 1
print(2 ** tmp - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
n_list = [0 for i in range(40)]
n_list[0] = 1
count = 1
ans = 0
while h > 1:
    h = h // 2
    n_list[count] = 1
    count += 1
for i in range(40):
    ans += n_list[i] * (2**i)
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

atc = 0
t = 0

while h != 1:
  h = h // 2
  atc += 2 ** t
  t += 1

print(atc + 2 ** t)

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:
def main():
    h = int(input())
    times = 1
    ans = 0
    while h >= 1:
        h //= 2
        ans += times
        times *= 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import floor, log2
from collections import deque

def main():
    H = int(input())
    n = floor(log2(H))
    ct = 0
    for i in range(n+1):
        ct += pow(2, i)
    print(ct)
    # M = deque([H])
    # ct = 0
    # while M:
    #     v = M.popleft()
    #     if v > 1:
    #         new_v = floor(v/2)
    #         M.append(new_v)
    #         M.append(new_v)
    #     ct += 1
    # print(ct)

        
    

main()

Submission status: Accepted

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 2 ** x 未満だとx段のピラミッド
H = ir()
x = 0
while True:
    if 2 ** x > H:
        break
    else:
        x += 1

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

print(answer)

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())
ans=1
num=1
while h!=1:
  num=num*2
  ans=ans+num
  h=h//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())


def an(n):
    if n == 1:
        return 1
    elif n == 2 :
        return 3
    else:
        return 2 * an(n//2) + 1

print(an(h))

Submission status: Accepted

Solution code:
def solve():
    H = int(input())
    
    ans = 0
    tmp_h, n = H, 1
    while 1 < tmp_h:
        ans += n
        n *= 2
        tmp_h = tmp_h // 2
    ans += n
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
H_start = H
cnt = 0
cnt_odd = 0
while H > 0:
  if H % 2 == 1:
    H -= 1

    cnt_odd += 1*2**cnt
  H = int(H/2)
  cnt += 1
print(2**cnt+H_start-cnt_odd-1)

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

def solve(h):
    n = 0
    while h:
        h //= 2
        n += 1
    print(2**n-1)

if __name__ == '__main__':
    h = int(sys.stdin.readline().strip())
    solve(h)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

def Attack(H):
    cnt = 0
    if H == 1:
        return 1
    else:
        return (2*Attack(H//2)+1)

print(Attack(H))

Submission status: Accepted

Solution code:
from math import floor

H = int(input())

i = 0
counter = 0
while H > 0:
    H = floor(H/2)
    i += 1
    counter += (2 ** (i-1))

print(counter)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    a = int(input())
    sum = 1
    count = 0
    while a >1:
        a = a // 2
        count = count +sum
        sum = sum *2

    print(count + sum )

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
H = int(input())
if H%2==0:
  ans=0
  l=1
  while True:
    ans+=l
    H=H//2
    l*=2
    if H==0:
      print(ans);break
else:
  ans=0
  l=1
  while True:
    ans+=l
    H=math.floor(H//2)
    l*=2
    if H==0:
      print(ans);break

Submission status: Accepted

Solution code:
H = int(input())
n = 0
while(H != 1):
    H = H//2
    n += 1
#print(n)
print(pow(2, n+1)-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import bisect
h=int(input())
ans=0
l=1
cnt=0
L=[]
for i in range(41):
    L.append(2**i)

n=bisect.bisect_right(L,h)-1
ans=sum(L[:n+1])
print(ans)

Submission status: Accepted

Solution code:
h=int(input())
a=0
for i in range(h):
    a+=2**i
    h//=2
    if h==0:
        break
print(a)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

count = 0
ans = 1
while H != 1:
    H = H // 2
    count += 1

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import bisect
import numpy as np
import math
import itertools
def main():
    H = int(input())

    bin_str = format(H, 'b')
    print(int("1" * len(bin_str), 2))


    return 0
if __name__ == '__main__':
    main()

Submission status: Accepted

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