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:
def main():
    h = int(input())
    ans = 0
    i = 0
    while ans < h:
        ans += 2 ** i
        i += 1
    print(ans)
    
      
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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



print(goukei+1)

Submission status: Accepted

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

import math


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

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

h = i()

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()

H = ini()


def solve(h):
    if h == 1:
        return 1
    return 1 + 2 * solve(h >> 1)


print(solve(H))

Submission status: Accepted

Solution code:
import math
h=int(input())
x=h
a=0
ans=0
while(h!=0):
  h=math.floor(h/2)
  a+=1
for i in range(0,a):
  ans+=pow(2,i)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
c = 1
while n > 1:
    n = n // 2
    c += 1
print(2**c-1)

Submission status: Accepted

Solution code:
n = int(input())
c = 0
i = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    H = int(input())
    ans = 1
    if H >1:
        x = 1
        while x<= H:
            x*= 2
        ans = x-1
    print(ans)


if __name__ == '__main__':
    solve()

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:
import math

H = int(input())

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

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

print(attack)

Submission status: Accepted

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

Submission status: Accepted

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

def solve(H: int):
    D = int(math.log2(H)) + 1
    cnt = 0
    for d in range(D):
        cnt += 2 ** d
    print(cnt)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
def a(h):
  if h<2:
    return 1
  return 1+2*a(h//2)
print(a(int(input())))

Submission status: Accepted

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

n = 0
H = int(input())
N = attack(H, n)

print(N)

Submission status: Accepted

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

h = int(input())

def hit(h, s):
    if h == 1:
        return s+1
    else:
        return 2 *hit(h//2, s) + 1

print(hit(h, 0))

Submission status: Accepted

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

# In[25]:


H = int(input())


# In[26]:


import math


# In[28]:


print(int(2**(math.log2(H)//1 + 1)-1))


# In[ ]:

Submission status: Accepted

Solution code:
print(~-(1<<len(bin(int(input()))[2:])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def attack(n):
    ans = 0
    if n == 1:
        ans += 1
    else:
        ans += 2*attack(n//2)+1

    return ans

h = int(input())
print(attack(h))

Submission status: Accepted

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

h = int(input())

print(battle(h))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
ans = 0
for i in range(50):
    if 2 ** i <= h and h < 2 ** (i+1):
        ans = (2**i) * 2 -1
print(ans)

Submission status: Accepted

Solution code:
h=int(input())
import math
count=0
kazu=1
hp=h
while hp:
  count+=kazu
  kazu*=2
  hp=math.floor(hp/2)
print(count)

Submission status: Accepted

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

for i in range(10**99):
  h = h//2
  count += 2**i
  if h == 0:
    print(count)
    exit()

Submission status: Accepted

Solution code:
h = int(input())

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

print(res)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

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

print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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


def solve(H: int):
    ans = 0
    tmp = 1
    while H:
        ans += tmp
        H //= 2
        tmp *= 2
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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())
def attack(x):
    if x<=1:
        return 1
    return 2*attack(x//2)+1
print(attack(H))

Submission status: Accepted

Solution code:
H=int(input())
x=1
while x<=H:
    x*=2
print(x-1)

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
s = len(bin(h)) - 2
x = 0
for i in range(s):
    x += 2**i
print(x)

Submission status: Accepted

Solution code:
H = int(input())


# 2 or 3が残った場合は、3回必要

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

print(leaf - 1)

Submission status: Accepted

Solution code:
#D
H=int(input())
cnt=0
ans=0
while True:
    ans+=pow(2,cnt)
    cnt+=1
    if H==1:
        break
    H=int((H-H%2)/2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    H = int(input().strip())
    return H,


def solve(H):
    monsters = 1
    attacks = 0
    while H > 1:
        attacks += monsters
        H //= 2
        monsters *= 2
    attacks += monsters 
    return attacks


if __name__ == "__main__":
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

H=I()

cnt = 1

while True:
  if H == 1:
    break
  H = math.floor(H/2)
  cnt += 1
ans= 0
for i in range(cnt):
  ans += 2 ** i
  
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

def dist(n):
    if n == 0:
        return 0
    if n == 1:
        return 1

    ret = 2 * dist(n // 2) + 1

    return ret

print(dist(h))

Submission status: Accepted

Solution code:
h = int(input())

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

print(attack(h))

Submission status: Accepted

Solution code:
### H を超えない2の累乗 * 2 - 1
H = int(input())
two_exps = []
two_exp = 2 ** 0
limit = 10 ** 12

while two_exp <= limit:
    two_exps += [two_exp]
    two_exp *= 2

for i, v in enumerate(two_exps):
    if v > H:
        print(two_exps[i - 1] * 2 - 1)
        break
else:
    print(two_exps[-1] * 2 - 1)

Submission status: Accepted

Solution code:

class abc_153:
    
    def __init__(self):
        pass
    def A(self):
        pass
    def B(self):
        pass
    def C(self):
        pass
    def D(self):
        H=int(input())
        count=1
        att_count=0
        
        while H>0:
            att_count+=count
            count*=2
            H>>=1
        print(att_count)
        
    def E(self):
        pass
    def F(self):
        pass
    
if __name__=='__main__':
    obj=abc_153()
    obj.D()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


sys.setrecursionlimit(10**5)


def main():
    h = gete(int)

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

    print(dfs(h))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input()) #モンスターの体力

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

print(attack(H))

Submission status: Accepted

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

print(2**cnt - 1)

Submission status: Accepted

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

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

    for i in range(40):
        if 2**(i+1) == h:
            n = i+2
            break
        if 2**(i) < h and h < 2**(i+1):
            n = i+1
            break
    ans = sum([2**i for i in range(n)])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h = int(input())

ans = 0

cnt = 1

while h != 0:
    h = h//2
    ans += cnt
    cnt *= 2
    
print(ans)

Submission status: Accepted

Solution code:
H=int(input())

def touhisum(a, r, n):
    return int(a*(r**n-1)/(r-1))

import math

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

print(touhisum(1,2,kaiso))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()


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

    bin_k = 0
    tmp = H
    while True:
        bin_k += 1
        tmp = tmp // 2
        if tmp == 0:
            break

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

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import math
def main():
    H = int(input())
    # 全てをそのまま追う場合
    # 10*1->5*2->2*4->1*8
    # 8*1->4*2->2*4->1*8
    # 7*1->3*2->1*4
    # 4*1->2*2->1*4
    # 2**0+2**1+...+2**round(log(H))
    k = int(math.log(H)/math.log(2))
    ans = 1
    tmp = 1
    for i in range(k):
        tmp *= 2
        ans += tmp
    print(ans)

main()

Submission status: Accepted

Solution code:
n = int(input())
count = 1
while(n):
	count *= 2
	n //= 2
print(count - 1)

Submission status: Accepted

Solution code:
#153d
h = int(input())

# (10 ** 12) / (1024 ** 4) < 1

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

for i in range(1, 41):
  h //= 2
  if h == 1:
    print(2 ** (i + 1) - 1)
    exit()

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

print(f(h))

Submission status: Accepted

Solution code:
h = int(input())

for i in range(h):
    if 2**i <= h and h < 2**(i+1):
        a = i
        break

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

print(ans)

Submission status: Accepted

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

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

    memo = {}
    def dfs(h):
        if h in memo:
            return memo[h]
        if h == 1:
            memo[1] = 1
            return 1

        ret1 = dfs(h//2)
        ret2 = dfs(h//2)
        memo[h] = ret1 + ret2 + 1
        return memo[h]

    ans = dfs(H)
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N=int(input())

cnt=0
tmp=N
for i in range(100):
    if tmp==1:
        break
    else:
        tmp=tmp//2
        cnt+=1
print(2**(cnt+1)-1)

Submission status: Accepted

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

l = []
n = 1

while n <= H:
    l.append(n)
    n *= 2
print(sum(l))

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

Solution code:
def fun(N):
	if(N == 1):
		return 1;
	return 2*fun(N//2)+1

n = int(input())
print(fun(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
count = 1
monster = 1
while True:
  if H == 1:
    break
  else:
    H = int(H / 2)
    monster = monster * 2
    count += monster
print(count)

Submission status: Accepted

Solution code:

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




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

two = [2**i for i in range(40)]
ix = bisect.bisect_right(two, H)

ans = 0
for i in range(ix):
    ans += two[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())
a=0
b=0
if h%2 != 0:
	h=h-1
c=h
while h > 1:
	h=int(h/2)
	a+=1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    h = int(input())
    count = 0
    while h != 0:
        count += 1
        if h == 1:
            h = 0
        else:
            h //= 2
    print(2**count-1)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for i in range(10**10):
    a = 2**i
    ans += a
    if a >= n:
        if a > n:
            ans -= a
        print(ans)
        break

Submission status: Accepted

Solution code:
H = int(input())
m = 1
at = 0
for i in range(H):
    if H == 1:
        at += m
        print(at)
        exit()
    at += m
    H //= 2
    m *= 2

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,int(math.sqrt(10**12))):
    if  h > ans:
        ans+= 2**i
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
h=int(input())
#a,b,x=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

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

print(count)

Submission status: Accepted

Solution code:
H = int(input())
from math import log, floor

N = floor(log(H)/log(2)) + 1
print(2**N-1)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from math import log2
from math import floor
def main():
    H = int(readline())
    print(2**(floor(log2(H))+1)-1)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(attack(h))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
n_o = n
count = 0
for i in range(1,100):
    n = n // 2
    count = count + 1
    if n <= 1:
        break
if n_o == 1:
    print(1)
else:
    print(2**(count+1)-1)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

while not K <= H < 2*K:
  K = 2*K

print(2*K-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# For taking integer inputs.
def inp():
    return(int(input()))


n = inp()
i = 1
while n > 1:
    n = int(n/2)
    i += 1
print(2**i - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(raw_input())

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

print f(h)

Submission status: Accepted

Solution code:
h=int(input())

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

Submission status: Accepted

Solution code:
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

h = readInt()

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

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

Submission status: Accepted

Solution code:
H = int(input())
r = 0
n = 1
h = H
while h > 0:
  r += n
  if h > 1:
    n = 2*n
    h = h//2
  elif h == 1:
    h = 0
print(r)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

h = ni()



def atk(n):
  if n==0:
    return 1

  n //=2
  return atk(n)*2

print(atk(h)-1)

Submission status: Accepted

Solution code:
m = int(input())
i = 0
count = 0
while 2**i <= m:
    count += 2**i
    i += 1

print(count)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
h=int(input())
def func(i):
  if i==1:
    return 1
  else:
    return func(i//2)*2+1
print(func(h))

Submission status: Accepted

Solution code:


def main():
    H = int(input())
    cnt = 1; ans = 1
    while H > 1:
        cnt = cnt*2
        ans += cnt
        H = H//2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())
cnt=0
for i in range(1,10**9):
    if H>1:
        H=H//2
        cnt+=1
    elif H==1:
        cnt+=1
        break
print(2**cnt-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

answer = 0
for i in range(0, depth+1):
    answer += pow(2, i)

print(answer)

Submission status: Accepted

Solution code:
h=int(input())
r=1
n=1
import math
while h>1:
  h=math.floor(h/2)
  n*=2
  r+=n
print(r)

Submission status: Accepted

Solution code:
enemie = int(input())

def attack(N, times=-1):
    times += 1
    if N // 2 == 0:
        return times
    else:
        enemie = N // 2
        return attack(enemie, times)

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

print(ans)

Submission status: Accepted

Solution code:
enemie = int(input())

times = -1
for i in range(enemie):
    times += 1
    if enemie >= 2:
        enemie //= 2
    else:
        break

ans = 0
for j in range(times+1):
    ans += 2**j
    
print(ans)

Submission status: Accepted

Solution code:
enemie = int(input())

times = 0
for i in range(enemie):
    times += 1
    if enemie >= 2:
        enemie //= 2
    else:
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

ans = 0
num = 0

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

print(ans)

Submission status: Accepted

Solution code:
h = int(input())
f = True
count = 0
while f:
    if 2**count<= h < 2**(count+1):
        f = False
    else:
        count += 1

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

print(ans+2**count)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    h = int(sys.stdin.readline())
    time = 0
    while(h != 0):
        h = h // 2
        time += 1
    print(pow(2,time)-1)
    return 0

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
H=int(input())

total=0
for i in range(10**2):
    H=int(H/2)
    if H>=1:
        total+=1
    else:
        break
attack=0
for i in range(total+1):
    attack+=2**(total-i)
print(attack)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def func(x):
    if x > 1:
        return 2 * func(x//2) + 1
    elif x == 1:
        return 1


H = int(input())

ans = func(H)
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

bi = bin(H)
bi2 = bi[2:]
ans = 2**len(bi2) - 1
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

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

print(cnt)

Submission status: Accepted

Solution code:
import math
A = int(input())
ans = 0
i = 1

while A > 1:
  A = math.floor(A/2)
  ans += i
  i *= 2


ans += i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    H = int(input())
    print(sum([2**i for i in range(math.floor(math.log2(H)+1))]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h=int(input())
t=0
for i in range(41):
    if(2**i>h):
        t=i
        break
ans=0
for i in range(t):
    ans+=2**i
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

add = 1
ans = 0
while(h!=1):
    h = h//2
    ans += add
    add *= 2
    
ans += add
print(ans)

Submission status: Accepted

Solution code:
H=int(input())

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

print(count)

Submission status: Accepted

Solution code:
H = int(input())

count = 0
monster_num = 1
monster_hp = H
while monster_hp != 0:
    count += monster_num
    monster_num *= 2
    monster_hp //= 2
print(count)

Submission status: Accepted

Solution code:
import math 
import sys 
#t=int(sys.stdin.readline())
t=1
for _ in range(t):
    n=int(input())
    x=0
    ans=0
    while(n>0):
        n//=2
        ans+=2**x 
        x+=1
    print(ans)

Submission status: Accepted

Solution code:
H  = int(input())

i = 0
ans = 0

while H != 1:
  H = int(H//2)
  i += 1

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

Submission status: Accepted

Solution code:
import sys
import math
import bisect
import re

d = dict()

def solve(n):
    global d
    if n not in d:
        if n == 1:
            d[n] = 1
        else:
            d[n] = 1 + 2 * solve(n // 2)
    return d[n]

def main():
    n = int(input())
    print(solve(n))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

h = int(input())
t = int(math.log2(h))
a = 2**(t+1)
print(a-1)

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

h = int(input())

# curr_n = 0
curr_2_njou = 1
while True:
    if h < curr_2_njou:
        break
    else:
        curr_2_njou*=2

print(curr_2_njou-1)