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
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

H = int(input())

def c(hp, cnt):
    if hp//2 > 0:
        return c(hp//2, cnt+1)
    else:
        return cnt+1

print(2**c(H, 0)-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    H=ii()
    c = 1
    ans = 0
    while H:
        ans += c
        H >>= 1
        c <<= 1
    print(ans)

main()

Submission status: Accepted

Solution code:
import sys


def main():
    h = int(sys.stdin.readline().strip())

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

    print(solve(h))


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def solve(inp):
    H = int(inp.readline().strip())

    n = 1
    r = 1
    while True:
        n *= 2
        if n > H:
            break
        r = r * 2 + 1

    return r


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

H = int(input())

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

print(calc(H))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
h = int(input())
ans = 0
num = 1
while True:
    if h == 1:
        ans += num
        break
    else:
        h = h//2
        ans += num
        num *= 2
print(ans)

Submission status: Accepted

Solution code:
h = int(input())

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

print(2 ** two - 1)

Submission status: Accepted

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

Submission status: Accepted

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

while h:
  h >>= 1
  n += 1
print(2**n - 1)

Submission status: Accepted

Solution code:
H = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

tmp = 1
ans = 1

while h != 1:
    h //= 2
    tmp *= 2
    ans += tmp

print(ans)

Submission status: Accepted

Solution code:
import math
def main():
    H = int(input())
    t = int(math.log2(H))
    r = 2**(t + 1) - 1
    print(r)
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

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

Submission status: Accepted

Solution code:
H=int(input())

k=1
N=0
while H>0:
  H=H//2
  N+=k
  k*=2
print(N)

Submission status: Accepted

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	H = int(input())
	ans = 1
	for i in range(50):
		if 2 ** i > H:
			ans = 2 ** i - 1
			break

	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
h = int(input())
T = [[h,1]]
s = 0

l = 10**6 + 3
A = [0] * l
A[1] = 1
for i in range(2, l):
    A[i] = 1 + A[i//2] * 2
a = 0
while s < len(T):
    if T[s][0] >= l:
        T.append([T[s][0]//2, T[s][1]*2])
        a += T[s][1]
        T[s] = [0,0]

    s += 1

# print(T)


for i in range(len(T)):
    a += A[T[i][0]] * T[i][1]
print(a)

Submission status: Accepted

Solution code:
import math

h = int(input())

n = math.floor(math.log2(h))
ans = 2**(n+1)-1

print(ans)

Submission status: Accepted

Solution code:
H = int(input())
h = H
result = 0
i = 1
while 0<h:
    h = H // (2**i)
    result += 2**(i-1)
    i += 1

print(result)

Submission status: Accepted

Solution code:
h = int(input())

num = 1
cnt = 0
while h != 1:
    # print(h)
    h = h // 2
    cnt += 1
    num *= 2
print(num + ((2 ** cnt) - 1))
# print(cnt*num)

Submission status: Accepted

Solution code:
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

h = ni()
c = 0
s = 1
while h > 1:
    h //= 2
    c += 1
    s += 2 ** c
print(s)

Submission status: Accepted

Solution code:
def hit(h):
    ans = 0
    if h == 1:
        ans += 1
    else:
        ans += 2*hit(h//2) + 1
    return ans
  
if __name__ == '__main__':
    print(hit(int(input())))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

i = 0
now = 0
while now < h:
    now = 2 ** i
    if now >= h:
        break
    i += 1

if 2 ** i == h:
    pass
else:
    i = i -1

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

result = 0
i = 1
while 'true':
    if H == 1:
        break
    else:
        H //= 2
        result += i
        i *= 2
        
        
print(result + i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0

for i in range(1, 40):
    if 2**i <= H: cnt += 1


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

print(ans)

Submission status: Accepted

Solution code:
import math
import sys
h = int(input())
#n, k = map(int, input().split())
#h = list(map(int, input().split()))

c = 1
while (True):
    if h <= 2 ** c - 1:
        print(2 ** c - 1)
        break

    c += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

Solution code:
from math import ceil,log2

def main():
    H = int(input())
    lg = log2(H)
    ans = 0
    cnt = 0
    while H > 0:
        ans += 2**cnt
        cnt += 1
        H = H // 2
    print(ans)
    return
if __name__ == "__main__":
    main()

Submission status: Accepted

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

while H > 1:
    H >>= 1
    bit_digit += 1

ans = (1 << bit_digit) - 1

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())


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


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

print(ans)

Submission status: Accepted

Solution code:
h = int(input())

count = 0

n = 1
while n <= h:
    count += n
    n *= 2
print(count)

Submission status: Accepted

Solution code:
h = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
# coding=utf-8
# Date: 2020-01-08
# Author: lee215

import heapq

get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]


H = get()

heap = [[H, 1]]
res = 0
while heap:
    h, n = heapq.heappop(heap)
    res += n
    if h == 1: continue
    heapq.heappush(heap, [h / 2, n * 2])

print res

Submission status: Accepted

Solution code:
import math
def A():
    temp = [int(i) for i in input().split()]
    print(int(math.ceil(temp[0]/temp[1])))

def B():
    temp = [int(i) for i in input().split()]
    H = temp[0]
    N = temp[1]
    A = [int(i) for i in input().split()]
    if H <= sum(A):
        print('Yes')
    else:
        print('No')

def C():
    temp = [int(i) for i in input().split()]
    N = temp[0]
    K = temp[1]
    H = [int(i) for i in input().split()]
    if N <= K:
        print(0)
        return
    H.sort(reverse=True)
    print(sum(H[K:]))

def D():
    H = int(input())
    factor = 0
    ans = 0
    while True:
        ans += 2**factor
        if H == 1:
            break
        H = math.floor(H/2)
        factor += 1
    print(ans)
D()

Submission status: Accepted

Solution code:
from sys import setrecursionlimit

setrecursionlimit(1000000)

H = int(input())


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

print(f(H))

Submission status: Accepted

Solution code:
h = int(input())

ans = 0
count = 0

while(True):
    if(h==1):
        ans += 2**(count)
        break

    h = h//2
    ans += 2**(count)
    count += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

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

Submission status: Accepted

Solution code:
h=int(input())



now=h
c=0
ans=0
while now>0:
    now=now//2
    ans+=2**c
    c+=1
#    print(c,now,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque, defaultdict
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10000000)

def Attack(L):
    if L == 1: return 1
    else:
        return 1 + 2 * Attack(L//2)

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

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

l = int(log(n, 2))
tmp = 1
ans = 0
for i in range(l+1):
    ans += tmp
    tmp *= 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

d = 1
while H >> d:
    d += 1

ans = (1 << d) - 1
print(ans)

Submission status: Accepted

Solution code:
h=int(input())

cnt=0
for i in range(10**5):
    cnt+=1
    h //=2
    if h == 0:
        print(2**cnt-1)
        exit()

Submission status: Accepted

Solution code:
h = int(input())

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



print(2 ** count - 1)

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import math

H=one_int()

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

print(2**beki -1 )

Submission status: Accepted

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


def solve(H: int):
    ans = 1
    x = 1
    while H != 1:
        H = H // 2
        x *= 2
        ans += x
    print(ans)
        


    return


# Generated by 1.1.6 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())

life = H
enemy = 1
ans = 1

while True:
    life //= 2
    if life <= 0:
        break
    enemy *= 2
    ans += enemy

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

x = 1
while H > 1:
    x = 1 + 2*x
    H //= 2

print(x)

Submission status: Accepted

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

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

    print(ans)


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
#N,K = list(map(int,input().split()))
#H = sorted(list(map(int,input().split())))
count = 0
while H > 0:
    H //= 2
    count +=1
bit = '1'*count
print(int(bit,2))

Submission status: Accepted

Solution code:
import math
H = int(input())
ans = 0
now_hp = H
now_numofmonster = 1
while (now_hp != 0):
    ans += now_numofmonster
    now_hp = math.floor(now_hp / 2)
    now_numofmonster *= 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())

k=0
count=0
while True:
    H=H//2
    count+=(2**k)

    if H==0:
        break
    k+=1


print(count)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    h = II()
    r = h
    ans = [1]
    while r > 0:
        r = r // 2
        if r > 0:
            ans.append(ans[-1] * 2)
    print(sum(ans))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h = int(input())
ht = list(format(h, 'b'))
n = len(ht)
result = 0
for i in range(n):
    result += 2**i
print(result)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  c=1
  h=I()
  ans=0

  while True:
    ans+=c
    if h==1:
      break

    h//=2
    c*=2

    # print(c,ans)

  return ans

# main()
print(main())

Submission status: Accepted

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


def main():
    h = int(input())
    res = solve(h)
    print(res)


def test():
    assert solve(2) == 3
    assert solve(4) == 7
    assert solve(1000000000000) == 1099511627775


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def main():
    h = inp()
    x = []
    while h>0:
        x.append(h%2)
        h //= 2
    s = sum(x)
    n = len(x)
    for i in range(n):
        if x[i] > 0:
            x[i] = s
            s -= 1
        else:
            x[i] = s
    ans = 0
    for i in range(n):
        ans += pow(2,i)
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def main():
    H = I()

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

    print(pow(2,count)-1)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import fractions
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

H = I()
print(tami(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
h=int(input())
c=math.log2(h)
c=math.floor(c)
ans=1
now=1
for i in range(c):
    now*=2
    ans+=now
print(ans)

Submission status: Accepted

Solution code:
import math
H = int(input())
f = [1]
for i in range(40):
    f.append(f[-1]+2**(i+1))
tmp = int(math.log2(H))
print(f[tmp])

Submission status: Accepted

Solution code:
def main():
    h = int(input())
    cnt = 0
    x = 1
    while h:
        cnt += x
        h //= 2
        x *= 2
    print(cnt)


main()

Submission status: Accepted

Solution code:
import math

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

H = int(input())

log2H = int(log2(H))
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

ans = 0
tmp = 1

while H:
    ans += tmp
    tmp *= 2
    H //= 2

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

H = int(input())
cnt = defaultdict(int)

def dfs(n):
  if cnt[n]:
    return cnt[n]
  else:
    if n == 1:
      return 1
    else:
      return 2 * dfs(n // 2) + 1

print(dfs(H))

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
k = 0
while True:
    if 2**k <= h < 2**(k+1):
        break
    else:
        k += 1
ans = 1
for i in range(k):
    ans = 2 * ans + 1
print(ans)

Submission status: Accepted

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

while True:
  max_ = 2 ** k - 1 
  if n <= max_:
    print(max_)
    break
  else:
    k += 1

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

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


sys.setrecursionlimit(1000000)


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


print(f(H))

Submission status: Accepted

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

def f(X):
    if X not in memo:
        if X == 1:
            memo[X] = 1
        else:
            memo[X] = 2 * f(X//2)
    return memo[X]

H = int(input())

memo = {}
ans = f(H)

print(ans*2-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
count = 1
times = 0
while H > 1:
    H >>= 1
    times += count
    count <<= 1
times += count
print(times)

Submission status: Accepted

Solution code:
h = int(input())

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

print(attack(h))

Submission status: Accepted

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

Submission status: Accepted

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

    print(ans + cnt)




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10**5+10
MOD = 10**9+7
spf = [i for i in range(MAXN)]
spf[0]=spf[1] = -1
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]

def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))

def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))

def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD

    return (num*(pow(den,MOD-2,MOD)))%MOD

def flush():
    return sys.stdout.flush()

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''

d = {}
def fun(n):

    if n==1:
        return 1
    if d.get(n):
        return d[n]
    ans = 0
    ans+=1+2*fun(n//2)

    d[n] = ans
    return d[n]

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

Submission status: Accepted

Solution code:
H = int(input())


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


print(attack(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os,sys
from io import BytesIO, IOBase

def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())

def gcd(x,y):
    while(y):
        x,y=y,x%y
    return x
    

mod=(10**9)+7

import math 
        
for i in range(1):
    h=ii()
    a=math.log(h,2)
    a=int(a)
    a+=1
    ans=pow(2,a)
    ans-=1 
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

count = 0
monster = 1
while H != 1:
    H //= 2
    count += monster
    monster *= 2
    # print(H, count, monster)
count += monster
print(count)

Submission status: Accepted

Solution code:
def fun(h):
    if h==1:
        return 1
    elif h==0:
        return 0
    else:
        return 2*fun(int(h/2))+1
h = int(input())
print(fun(h))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

# print(ans)


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

    if ans >= h:
        print(ans)
        break

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
from math import log2

H = int(input())
N = int(log2(H))
r = 1
for i in range(N):
    r += (2**(1+i))
print(r)

Submission status: Accepted

Solution code:


def resolve():
    H=int(input())
    nom=1
    count=0
    while H!=0:
        H//=2
        count+=nom
        nom *=2
    print(count)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

ans = 0
attack = 1
while(True):
    ans += attack
    H = H //2
    attack = attack *2

    if(H==0):
        break


print(ans)

Submission status: Accepted

Solution code:
h = int(input())

ans = 0

x = 1

while h > 0:
    h = h // 2
    ans += x
    x *= 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

#a = list(map(int, input().split()))


a = int(input())

times=0

for i in range(999):
    if(a==0):
        break
    a = a//2
    times+=1
    


print(2**times-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

H, = map(int, input().split())

ans = 0
c = 0
while H != 0:
    H = int(H / 2)
    if c == 0:
        ans += 1
    else:
        ans += 2 ** c
    c += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

h = int(sys.stdin.readline().rstrip())

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

if __name__ == '__main__':
    ans = main()
    print(ans)