Problem:


Score : 400 points

Problem Statement

Caracal is fighting with a monster.

The health of the monster is H.

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

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

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

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

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

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

Constraints

1 \leq H \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H

Output

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

Sample Input 1

2

Sample Output 1

3

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

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

Sample Input 2

4

Sample Output 2

7

Sample Input 3

1000000000000

Sample Output 3

1099511627775



Sample input:
2


Sample output:
3

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

h = ni()

ans = 0
a = h // 2
c = 0
while h != 0:
    ans += 2 ** c
    h //= 2
    if c == 0:
        c += 1
    else:
        c += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def lb(x):
    return math.log(x)/math.log(2)


H=int(input())
idx=math.floor(lb(H))
tb= []
tb.append(1)
i=0
while i<50:
    i+=1
    tb.append(1+2*tb[-1])

print(tb[idx])

Submission status: Accepted

Solution code:
H = int(input())

for i in range(41):
#     print(i,2**i)
    if H < 2**i:
        kaisu = 2**(i)-1
        break
    elif H == 2**i:
        kaisu = 2**(i+1)-1
        break
        
print(kaisu)

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

count = 0

while health != 0:
    health = health // 2
    count += 1

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

Submission status: Accepted

Solution code:
h = int(input())
cnt = 0
for _ in range(h):
    h //= 2
    cnt += 1
    if h == 0:
        break
print(2**cnt -1)

Submission status: Accepted

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

n = math.floor(math.log2(h))

print(int(str('1')*(n+1),2))

Submission status: Accepted

Solution code:
H = int(input())

ans=0
n=1
while(H!=1):
    ans+=n
    H = int(H/2)
    n=n*2
    #print("ans:", ans)
    #print("n:", n)
    
print(ans+n)

Submission status: Accepted

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

    for i in range(50):
        if h < 2**i:
            print(2**i - 1)
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a=int(input())
t=1
j=0
p=1
while a!=1:
  if a%2==0:
    a/=2
    t+=1
    continue
  else:
    a=(a-1)/2
    t+=1
for i in range(t):
  j+=p
  p*=2
print(j)

Submission status: Accepted

Solution code:
H = int(input())

import math
n = int(math.log(H, 2))

ans = 0
for i in range(n + 1):
    ans += pow(2, i)
    
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

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

print(2 ** count - 1)

Submission status: Accepted

Solution code:
h = int(input())

count = 0
while True:
  if h <= 0:
    break
  h = h // 2
  count += 1

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

print(total)

Submission status: Accepted

Solution code:
import math

H = int(input())

h = math.log2(H)
h = math.floor(h)
h += 1
print(2**h-1)

Submission status: Accepted

Solution code:
h = int(input())
cnt = 0
lists = []
while h != 1:
    cnt += 1
    h = h//2
    lists.append(2**cnt)
print(sum(lists)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

H2 = H

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



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

print(ans)

Submission status: Accepted

Solution code:
import math
#n,k=list(map(int,input().split()))
#a=list(map(int,input().split()))
n=int(input())
tmp=bin(n)[2:]
ans=1
for _ in range(len(tmp)-1):
    ans=ans*2+1
print(ans)

Submission status: Accepted

Solution code:
h=int(input())

count=0

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

print(2**i-1)

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0
ls = []

while H >= 2:
    cnt += 1
    ls.append(int(2 ** cnt))
    H //= 2


print(sum(ls) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
a = int(input())
b = math.ceil(math.log2(a))
print(2**(b+1) - 1 if a == 2** b else 2**b - 1)

Submission status: Accepted

Solution code:
h = int(input())

count = 0
while h != 1:
    h //= 2
    count += 1

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

Submission status: Accepted

Solution code:
import math

h = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def num_attack(h):
    if h == 1:
        return 1
    else: # h % 2 == 0:
        return 1 + 2 * num_attack(h//2)

H = int(input())

print(num_attack(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
h = int(input())
if math.ceil(math.log2(h)) == math.floor(math.log2(h)):
    print(pow(2,math.ceil(math.log2(h*2)))-1)
else:
    print(pow(2,math.ceil(math.log2(h)))-1)

Submission status: Accepted

Solution code:
import numpy
H = int(input())
sum = 0
cnt = 0
if(H == 1):
	print(1)
	exit()
while H > 1:
	#print(H)
	sum += 2**cnt
	H/=2
	numpy.ceil(H)
	H = int(H)
	cnt+=1
print(sum+2**(cnt))

Submission status: Accepted

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

if H == 1:
  print (1)
  sys.exit()
if H >= 2:
  for i in range (0,100):
    if 2 ** i > H:
      r = i
      break
ans = 2 ** r - 1
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

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

print(c)

Submission status: Accepted

Solution code:
def attack(x, count):
  
  if x > 1:
    count += 1  # 分裂した回数を＋１
    x = int(x / 2)  # 小数点以下を切り捨て（Mathモジュールを使わないでやる方法）
    count = attack(x, count)  # 再帰的に呼び出す
  return count

h = int(input())
count = attack(h, 0) + 1
print(pow(2, count) - 1)

Submission status: Accepted

Solution code:
import numpy as np
h = int(input())
def battle(x):
    if x==1: return 1
    else:
      return 1 + 2 * battle(int(np.floor(x/2)))
ans = battle(h)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
cut=2**(len(str(bin(int(input())))[2:])-1)
cut+=cut-1
print(cut)

Submission status: Accepted

Solution code:
import math


h = int(input())

if h == 1:
    print(1)
    exit()
n = 0
while True:

    h = math.floor(h/2)
    if h <= 1:
        n += 1
        break
    else:
        n += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
n = 1
T = 1
while(H>1):
    H = H //2
    T += 2**n
    n +=1
    #print(H,T,n)
print(T)

Submission status: Accepted

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

H = int(input())
cnt = 0
ans = 1
while True:
    cnt += 1
    if H == 1:
        break
    H = H // 2
    ans += 2 ** cnt
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

# INF = float('inf')

# dp = [INF for i in range(H+10)]
# dp[0] = 0
# dp[1] = 1

# for i in range(1, H+1):

#     dp[i+1] = min(dp[i+1], dp[(i+1)//2] * 2 + 1)

# print(dp[H])

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

Submission status: Accepted

Solution code:
H = int(input())

def atk(h, n):
    if(h==1):
        return n
    else:
        hnew = h//2
        n += 1
        return atk(hnew, n)

def s(n):
    return (2**n - 1)
    
print(s(atk(H,1)))

Submission status: Accepted

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

n = 0
while(H != 1):
    H //= 2
    n += 1

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

Submission status: Accepted

Solution code:
h=int(input())

out=1
c=0

while h>1:
    h=h//2
    c+=1
    out+=2**c

print(out)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

def atk(H,n,cnt):
  if H == 1:
    cnt += n
    print(cnt)
  elif H > 1:
    cnt += n
    atk(H//2,n*2,cnt)
        
atk(H,1,0)

Submission status: Accepted

Solution code:
def resolve():
    H = int(input())
    import math
    print(int('1'*(int(math.log2(H))+1), 2))
resolve()

Submission status: Accepted

Solution code:
h = int(input())

l = len(bin(h)) - 2
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
H = int(input())

count = 0
for i in range(99999999999999999999999):

    # 攻撃の実施
    count += 2 ** i

    q, r = divmod(H, 2)

    # モンスター消滅
    if q == 0:
        print(count)
        exit(0)

    H = q

Submission status: Accepted

Solution code:
import math 
h = int(input())
ans = 0
t = int(math.log2(h)+1)

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

Submission status: Accepted

Solution code:
import math

def main():
  H = int(input())
  
  n = math.floor(math.log(H,2))
  
  Ans = 0
  
  for i in range(n+1):
    Ans += math.pow(2,i)
    
  print(int(Ans))
  return 0

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
H = int(input())

bin_H = format(H, 'b')

len_bin = len(bin_H)

max_digit_num = 2 ** (len_bin-1)
print(max_digit_num + max_digit_num -1)

Submission status: Accepted

Solution code:
h=int(input())
sum=h
devide=0
while h>1:
	#print("h:",h,"sum:",sum,"devide:",devide)
	sum+=2**devide
	if h%2==1:
		sum-=2**devide
	devide+=1
	h=int(h/2)

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

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

print(ss + 2 ** count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(100)

H = int(input())

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

print(f(H))

Submission status: Accepted

Solution code:
H = int(input())

for i in range(1,100):
    if H < 2**i :
        print(2**i - 1)
        break

Submission status: Accepted

Solution code:
from math import floor
N = int(input())
count = 1
sums = 1
while True:
    if N == 1:
        break
    N = floor(N/2)
    count = count * 2
    sums = sums + count
print(sums)

Submission status: Accepted

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

Submission status: Accepted

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

while H != 0:
    i += N
    N *= 2
    H = int(H/2)

print(i)

Submission status: Accepted

Solution code:
X = int(input()) #整数
result = 2 ** (len(bin(X)) - 2) - 1

print(result)

Submission status: Accepted

Solution code:
def attack(x):
    if x <= 1:
        return 1
    else:
        ans = 0
        ans += attack(int(x / 2))
        ans *= 2
        ans += 1
        return ans

h = int(input().rstrip())
at = attack(h)

print(at)

Submission status: Accepted

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

def atack(tairyoku):
    if tairyoku == 1:
        return 1
    else:
        return 1 + atack(int(tairyoku/2)) * 2

H = int(input())

ans = atack(H)

print(ans)

Submission status: Accepted

Solution code:
def main():
	n = int(input())
	s = 0
	while 2 ** s <= n:
		s += 1

	print(2 ** (s) -1)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
def attack(H):
    if H == 1:
        return 1
    elif H > 1:
        new_H = H // 2
        return 1 + attack(new_H) * 2

H = int(input())

print(attack(H))

Submission status: Accepted

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

# N = 7
X = int(math.log2(N))
# X

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

H = int(input())

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

times = 1
while H != 1:
    H //= 2
    times += 1

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

print(str(ans))

Submission status: Accepted

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

h = int(input())
res = 0
counter = 0

while h > 0:
    h = h // 2
    res += 2**counter
    counter += 1

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

a+=monster
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
import math
num = math.log(N, 2)
#print(num)
ansnum = int(num//1) + 1
#print(ansnum)
ans = 2**ansnum -1
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

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

print(attack(h))

Submission status: Accepted

Solution code:
H = int(input())

import math
def get_depth(x):
  if math.floor(x/2) == 0:
    return 1
  else:
    return get_depth(math.floor(x/2)) + 1

depth = get_depth(H)

ans = 0
for i in range(depth):
  ans = ans + math.pow(2, i)

print(int(ans))

Submission status: Accepted

Solution code:
import math
h = int(input())
count = 1
result = 0

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

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

print(result)

Submission status: Accepted

Solution code:
h=int(input())
c2=0
for i in range(0,41):
    if 2**i <= h and h < 2**(i+1):
        c2=i+1
        break
print(2**c2-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

counter = 0
hit_count = 0

while n!=1:
  n = n//2
  counter += 1
  hit_count += 2**counter
  #print(hit_count)
  
print(hit_count+1)

Submission status: Accepted

Solution code:
import math
import calendar
import fractions
import itertools

h = int(input())

a = 0

while 1:
    if 2 ** a > h:
        a -= 1
        break
    a += 1

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

print(ans)

Submission status: Accepted

Solution code:
H=int(input())
def counter(k):
    if k//2==0:
        return 1
    
    return 1+2*counter(k//2)
print(counter(H))

Submission status: Accepted

Solution code:
H = int(input())

h = H
for i in range(h):
    if(h == 1):
        break
    h //=  2
n = i

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

print(ans)

Submission status: Accepted

Solution code:
H=int(input())
import math 
a=math.log2(H)
z,x=math.modf(a)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
i=int(input())

cnt = 0
while True:
  cnt += 1
  n = i/2
  if n < 1:
    break
    
  i = n
  
ans = []
for i in range(cnt):
  ans.append(pow(2,i))
  
  
print(sum(ans))

Submission status: Accepted

Solution code:
from collections import deque

H = int(input())

l = [H]
q = deque(l)
ans = 0

def attack(ans,q):
    if len(q) == 0:
        print(2**ans-1)
        exit()
    else:
        a = q.popleft()
        if a == 1:
            ans += 1
        else:
            ans += 1
            q.append(a//2)
    return ans , q

while True:
    ans , q = attack(ans,q)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc153/tasks/abc153_d
H = int(input())

v = H
values = []
while v != 0:
    values.append(v)
    v = v // 2
values = sorted(values)
# print('values', values)

cost = [0 for _ in range(len(values))]
# print('cost', cost)
for i in range(len(cost)):
    if i == 0:
        cost[i] = 1
    else:
        cost[i] = cost[i - 1] * 2 + 1
# print('cost', cost)
print(cost[-1])

Submission status: Accepted

Solution code:
H = int(input())
log = list()
x = 1
while True:
  H = H // 2
  log.append(x)
  if H == 0:
    break
  x *= 2

print(sum(log))

Submission status: Accepted

Solution code:
h=int(input())
def fun(x,ans,counter):
  
  if x<2:
    ans+=counter
    return ans
  ans+=counter
  counter+=counter
  return fun(x//2,ans,counter)
print(fun(h,0,1))

Submission status: Accepted

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

def solve(H: int):
    ans=len(str(bin(H)))-2
    print(2**ans-1)

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

for i in range(50):
    if 2 ** i <= h:
        continue
    else:
        break

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:

def solve(H):
	if H == 1:
		return 1
	
	ans = 0
	count = 1	
				
	while H >= 1:
		ans += count
		
		H = H // 2
		count *= 2
		
	return ans
	
H = int(input().strip())
print(solve(H))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
N = int(input())
ans = 0
for i in range(int(math.log(N, 2))+1):
    ans += 2 ** i

print(ans)

Submission status: Accepted

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

AN=0

while H>=1:
    H=math.floor(H/2)
    AN+=1

print(2**AN-1)

Submission status: Accepted

Solution code:
from sys import stdin
H = int(stdin.readline().rstrip())
ans = 1
while ans <= H:
    ans = ans * 2
print(ans-1)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
h = int(input())
fix = 1

while h >= fix:
  fix *= 2

print(fix - 1)

Submission status: Accepted

Solution code:
# coding:UTF-8
H = int(input())
att = 0
monster_cnt = 1
while H != 1:
    H = int(H / 2)
    att += monster_cnt
    monster_cnt *= 2
print(att * 2 + 1)

Submission status: Accepted

Solution code:
hp = int(input())
pow_2 = len(bin(hp)) - 3

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

Submission status: Accepted

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

b=0
for i in range(c):
  b+=2**i
print(b)

Submission status: Accepted

Solution code:
def resolve():
    d = 1
    h = int(input())
    s = h
    a =0
    while 1 <= s:
        a += d
        s /=2
        d*=2
    print(a)

resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

hits = 0
steps = 1
while H != 1:
    H //= 2
    steps += 1
for x in range(steps):
    hits += pow(2, x)

print(hits)

Submission status: Accepted

Solution code:
H = int(input())

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

print((2**i-1))

Submission status: Accepted

Solution code:
h = int(input())

div_count = 0
add = 0
total_count = 0

while True:
    if h == 1:
        break
    h = h // 2
    if add == 0:
        div_count += 1
        add += 1
    else:
        div_count += add * 2
        add *= 2

if div_count == 0:
    total_count = 1
else:
    total_count = div_count + (add * 2)

print(total_count)

Submission status: Accepted

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

if h == 1:
  print(1)
  sys.exit()
cnt = 0
while h != 1:
  h = h // 2
  cnt += 1
  
print(2**(cnt+1)-1)

Submission status: Accepted

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

N = 0
flag = True
while flag:
  if H<2**N:
    flag = False
  else:
    N += 1

ans = 2**N - 1

print(ans)

Submission status: Accepted

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

a = 1
b = 0
while ( a <= H):
    a *= 2
    b += 1

print(2**b-1)

Submission status: Accepted

Solution code:
H = int(input())

num = 0
while True:
    if H == 1:
        break
    else:
        if H % 2 == 0:
            H = H // 2
            num += 1
        else:
            H = (H - 1) // 2
            num += 1
print(pow(2, num + 1) - 1)

Submission status: Accepted

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

h = int(input())

c = 0

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

print(2**c - 1)

Submission status: Accepted

Solution code:
h = int(input())

dp = [0, 1]

for i in range(2, 100001):
    x = 1 + 2 * dp[i // 2]
    dp.append(x)


if h < 100001:
    print(dp[h])



else:
    l = []
    y = h
    while y >= 100001:
        l = [y] + l
        y = y// 2
    ans = 1 + 2 * dp[l[0] // 2]
    if len(l) > 1:
        for i in range(len(l) - 1):
            ans = 1 + 2 * ans
    print(ans)

Submission status: Accepted

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

h = int(input())
out = 1
count = 1

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

print(out)

Submission status: Accepted

Solution code:
import sys
import math
H = int(input())
if H == 1:
    print(H)
    sys.exit()
n = 0
while H!=1:
    H = H//2
    n += 1
print(2**(n+1)-1)

Submission status: Accepted

Solution code:
h = int(input())
i = 0
kazu = 1
kaisuu = 0


while(1):
    kaisuu = kaisuu + kazu
    if(h>1):

        kazu = kazu * 2
        h = h//2
    else:

        print(kaisuu)
        break

Submission status: Accepted

Solution code:
H = int(input())

count = 1
while True:
    if not H > 1:
        break
    H = H // 2
    count += 1

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

Submission status: Accepted

Solution code:
H = int(input())

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

print(ans)

Submission status: Accepted

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

while True:
    if h != 1:
        h = int(h/2)
        count += 1
    else:
        break

x = [2**i for i in range(count+1)]
print(sum(x))

Submission status: Accepted

Solution code:
import numpy as np

H = int(input())

if H == 1:
  print("1")
else:
  c = 0
  h = H
  while(h>1):
    h //= 2
    c += 1
  
  p = 1
  q = 0
  for i in range(c+1):
    q += p
    p *= 2
  print(q)

Submission status: Accepted

Solution code:
h=int(input())
count=0
ans=0
while True:
    h=h//2
    count+=1
    if h==0:
        break
for i in range(1,count+1):
    ans+=2**(i-1)
print(ans)

Submission status: Accepted

Solution code:
import math

h = int(input())

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


print(ans)

Submission status: Accepted

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

x=int(input())
print(f(x))

Submission status: Accepted

Solution code:
import sys,collections,math,random,fractions,bisect;sys.setrecursionlimit(10**7)
sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n")
def I(i=0): t = [int(x)-i for x in sr().split()];return t 
def S(): t = sr().split(); return t if len(t) > 1 else t[0]
L1,L2,L3,L4, = [],[],[],[]

H, = I()
c = 0
while H > 0:
    H = H//2
    c += 1
ans = 0
for i in range(c):
    ans += 2**i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())

ans=0
counter=1
for i in range(50):
    if n>0:
        ans+=2**i
        n=n//2
    elif n==0:
        break
print(ans)

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):
            ans += 2**(i)
            if i == count-1:
                ans += 2**(i+1)
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h=int(input())
cnt=1; ans=0
def attack(h,cnt,ans):
    if h==1: return ans+1
    h=h//2; cnt*=2; ans+=cnt
    return attack(h,cnt,ans)
print(attack(h,cnt,ans))

Submission status: Accepted

Solution code:
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
H = int(input())
n = 0
while True:
    if H == 1: 
        break
    n = n + 1
    H= H // 2

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

Submission status: Accepted

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

while H!=1:
  H=H//2
  count+=1
  
print(2**count-1)

Submission status: Accepted

Solution code:
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

import itertools as iter
import math
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

H = num()
e_num = 1
enemies = [H]
ans = 0
while 1:
    if H == 1:
        ans += e_num
        break
    H = math.floor(H/2)
    ans += e_num
    e_num *= 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

i = 0
while True:
    tmp = pow(2, i)
    if H < tmp:
        break
    i += 1

#print(i)
print(pow(2,i)-1)

Submission status: Accepted

Solution code:
h = int(input())
n = 0
l = []
ans = 1
for i in range(42):
    l.append(2**i)

for i in range(1,41):
    if l[i]<=h<l[i+1]:
        ans=sum(l[:i+1])

print(ans)

Submission status: Accepted

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

h = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

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

print(count + 2**set_count)  # 分裂させる回数 +  体力１のモンスター数

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

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

print(cnt * 2 - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

count = 0
width = 0

while(1):
  if h == 1:
    count += pow(2,width)
    break
  if h >=2:
    if h%2 == 1:
      h = h-1
    h = h//2
    count += 1*pow(2,width)
    width += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

if 2**i==H:
  for k in range(i+1):
    Sum+=2**k
else:
  for k in range(i):
    Sum+=2**k
print(Sum)

Submission status: Accepted

Solution code:
H = int(input())

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

print((2 ** ans) - 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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