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 count_x(x):
    """
    O(logx)
    """
    if x == 1: return 1
    return 2*count_x(x//2)+1
    

print(count_x(int(input())))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

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

    print(dfs(H))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
H = float(input())
enemy_list = [H, 1]
attack_times = 0
while (len(enemy_list) > 0):
  enemy_hp = enemy_list[0]
  enemy_num = enemy_list[1]
  attack_times += enemy_num
  if (enemy_hp == 1):
    enemy_list = []
  if (enemy_hp > 1):    
    new_enemy_hp = math.floor(enemy_hp/2)
    new_enemy_num = enemy_num * 2
    enemy_list[0] = new_enemy_hp
    enemy_list[1] = new_enemy_num
print(attack_times)

Submission status: Accepted

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


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


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

i = 1
while H > 1:
    ans += 2 ** i
    H //= 2
    i += 1

print(ans)

Submission status: Accepted

Solution code:

h = int(input())

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

Submission status: Accepted

Solution code:
import math

def main():
  H = float(input())
  cnt = 0
  ans = 1
  
  while H > 1:
    H = math.floor(H / 2)
    #print(H)
    cnt += 1
    ans += 2 ** cnt
  
  #print(int(2 ** cnt))
  print(ans)
  
main()

Submission status: Accepted

Solution code:
n = int(input())

i = 0

while n>1:
    n//=2
    i += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

H = i()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
MAXN = 10 ** 6

dn = [None for _ in range(MAXN + 1)]


def n_attack(i):
    if i == 1:
        return 1
    elif i > MAXN:
        return 1 + 2 * n_attack(i // 2)
    elif dn[i] is not None:
        return dn[i]
    else:
        n = 1 + 2 * n_attack(i // 2)
        dn[i] = i
        return n

answer = n_attack(h)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

total = 0
count = 0
while H>0:
    H = H//2

    total += 2**count
    count += 1

print(total)

Submission status: Accepted

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

if h == 1:
    print(1)
    sys.exit()
ans = 1
while h > 0:
    ans *= 2
    h //= 2

print(ans-1)

Submission status: Accepted

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

h = int(input())
print(func(h))

Submission status: Accepted

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

H=int(input())
print(f(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

Solution code:
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    H = int(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = 0
    attack = 1
    while H > 1:
        ans += attack
        attack *= 2
        H = H // 2
    print(ans + attack)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# n, m, l = map(int, input().split())

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

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

MP = int(input())
M = 1
ans = 0

while MP > 1:
    ans += M
    M = 2*M
    MP = MP//2
ans += M

print(ans)

Submission status: Accepted

Solution code:
h = int(input())

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

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

print(ans)

Submission status: Accepted

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

H = int(input())

print(dfs(H))

Submission status: Accepted

Solution code:
h=int(input())

import math

count=0
for i in range(0,h):
  if h < 1:
    break
  h = math.floor(h/2)
  count += 2**i
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

ans = 0
count = 1

while(H):
    ans += count
    count *= 2
    H //=  2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import log2
H = int(input())
n = H.bit_length()
print(pow(2, n) - 1)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h = int(input())
d = {}
def sub(h):
    if h in d:
        return d[h]
    if h==1:
        ans = 1
    else:
        ans = sub(h//2) * 2 + 1
    d[h] = ans
    return ans
print(sub(h))

Submission status: Accepted

Solution code:
H = int(input())


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


print(f(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a=0
for i in range(0,100):
    if 2**i<=N<2**(i+1):
        a=i
        break
        
ans=1
for i in range(a):
    ans=2*ans+1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
lst = [2**i for i in range(45)] 
for i in range(45) :
    if lst[i] <= H <= lst[i+1]-1 :
        print(lst[i+1]-1)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
lst = [2 ** i for i in range(45)]
for i in range(45):
  if lst[i] <= h <= lst[i + 1] - 1:
    print(lst[i + 1] - 1)
    exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

for i in range(1, 10**6):
    x = 2 ** (i-1)
    y = 2 ** i - 1
    if x <= H <= y:
        ans = y
        break

print(ans)

Submission status: Accepted

Solution code:
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

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:
import math
def f(H):
    if H==1:
        return 1
    else:
        return(2*f(math.floor(H/2))+1)
H=int(input())
print(f(H))

Submission status: Accepted

Solution code:
import sys
from math import floor
def main():
    h = int(input())
    r = 0
    n = 1
    while True:
        if h == 1:
            r += n
            print(r)
            sys.exit()
        else:
            h = floor(h/2)
            r += n
            n *= 2

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    H = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    cur=1
    tot=0
    while H>0:
        tot+=cur
        H=int(H*0.5)
        cur*=2

    print(tot)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

h = int(input())

t = 1
e = 1
while h > 1:
    h = math.floor(h / 2)
    e *= 2
    t += e

print(t)

Submission status: Accepted

Solution code:
h = int(input())
cnt = 0
temp = []
temp.append(1)
while h > 1:
    h = h//2
    cnt += 1
    temp.append(2**cnt)

print(sum(temp))

Submission status: Accepted

Solution code:
h = int(input())

def main(i):
  if i == 1:
    return 1
  else:
    c = main(i//2)*2+1
    return c

print(main(h))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())

if H == 1:
  ans=1
  
H_list=[]
while H > 1:
    if H % 2 != 0:
        H=H-1
    H_list.append(H)
        
    H = H//2
    
H_list.sort()
 
ans_list=[]
for h in H_list:
    if h == 2:
        ans = 3
    else :
        ans = 2*ans+1
    ans_list.append(ans)
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def mon(h, n, k):
  if h > 1:
    h = math.floor(h / 2)
    k += n
    n *= 2
    return mon(h, n, k)
  elif h == 1:
    k += n
    return k
h = int(input())
n = 1
k = 0
print(mon(h, n, k))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

#####################################################################################

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)












###################################################################

def main():
    #CODE GOES HERE:
    h=ii()
    l=int(math.log(h,2)+1)
    print(int((2**l -1)))












    
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Accepted

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

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

attack = 2 ** c - 1
print(attack)

Submission status: Accepted

Solution code:
h = int(input())
from math import log
d = int(log(h,2))
ans = 0
for i in range(d+1):
    ans += 2**i
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

n = len(bin(H))-2

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

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(H):
    ans = 0
    monster = 1
    while True:
        ans += monster
        if H == 1:
            break
        H = H // 2
        monster *= 2
    print(ans)


if __name__ == '__main__':
    H = int(input())
    solve(H)

Submission status: Accepted

Solution code:
# Problem D - Caracal vs Monster

# input
H = int(input())

# initialization
attack_dic = {}

# calc
def calc_count(h, attack):

    if h in attack_dic:
        return attack_dic[h]

    h = h // 2
    if h>0:
        attack += calc_count(h, attack) * 2 + 1
        attack_dic[h] = attack
        return attack
    else:
        return 1
ans = calc_count(H, 0)

# output
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

ans = 1
while h:
  h //= 2
  ans *= 2
  
ans -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = int(input())

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

print(haha(x))

Submission status: Accepted

Solution code:
import math
H = int(input())
bit =math.floor(math.log(H,2))

print(pow(2,bit)*2-1)

Submission status: Accepted

Solution code:
import math
h = int(input())
hp = h
c = 0
ans = 0

while hp > 1:
    hp = math.floor(hp/2)
    c += 1
for i in range(0,c+1):
    ans += 2 ** i
print(ans)

Submission status: Accepted

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

if H == 1:
    print(1)
    
else:
    while H >= 4:  # H < 4 になったときに抜ける
        H = H // 2
        n += 1
    print(4 * (2 ** n) - 1)

Submission status: Accepted

Solution code:
H=int(input())

def dfs(h):
    if h==1:
        return 1
    else:
        if h%2==0:
            return dfs(h//2)*2+1
        else:
            return dfs((h-1)//2)*2+1

print(dfs(H))

Submission status: Accepted

Solution code:
from sys import setrecursionlimit
setrecursionlimit(1000000)

H = int(input())

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

Submission status: Accepted

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

H = int(input())
count = 1
tmp = 2

while H > 1:
    count += tmp
    tmp = tmp * 2
    H = H//2

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())
m=1
a=0

while H>1:
    a=m
    H=H//2
    _m=2*m
    m=_m

print(2*m-1)

Submission status: Accepted

Solution code:
n=int(input())
i=0
while(1):
    if n==1:
        break
    n//=2
    i+=1
i=bin(i+1)[2:]
ans=1
mkr=2
for j in i[::-1]:
    if j=="1":
        ans*=mkr
    mkr*=mkr
print(ans-1)

Submission status: Accepted

Solution code:
h = int(input())

n = 1
while True:
    tmp = 2**(n) -1
    if h <= tmp :
        print(tmp)
        exit()
    n += 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

h = int(input())
cont=1

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

Submission status: Accepted

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


print(2 * pow(2, math.floor(math.log2(h))) - 1)

Submission status: Accepted

Solution code:
H=int(input())
ans=0
a=H
b=0
while a!=1:
  a=a//2
  ans+=2**b
  b+=1
else:
  ans+=2**b
print(ans)

Submission status: Accepted

Solution code:
#

import sys
input=sys.stdin.readline

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

Submission status: Accepted

Solution code:
h = int(input())

m = 1
a = 0
while h > 1:
    h //= 2
    a += m
    m *= 2
a += m
print(a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
H = int(input())

def cal(H):
    if H > 1:
        return 2 * cal(int(H/2)) + 1
    else:
        return 1
print(cal(H))

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
h = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H = int(input())
    ret = 0
    current = 1
    while H:
        ret += current
        H = H // 2
        current *= 2
    print(ret)

if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
H = int(input())
memo = {}
def attack(h):
  if h in memo: return memo[h]

  if h <= 1:
    memo[h] = 1
    return memo[h]
  else:
    memo[h//2] = attack(h//2)
    return 1 + memo[h//2] + memo[h//2]

print(attack(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

TwoExp = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776]
for i in range(41):
  if H < TwoExp[i]:
    print(TwoExp[i]-1)
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

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

Submission status: Accepted

Solution code:
H = int(input())
for i in range(10**5):
    if 2**i <= H < 2**(i+1):
        print(2**(i+1)-1)
        break

Submission status: Accepted

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

print(rec(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    import sys
    sys.setrecursionlimit(1000000)
    H = int(input())

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

    print(battle(H))

    return


resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    h = int(input())
    attack = 0
    cnt = 0
    while h >= 2:
        h //= 2
        cnt += 1
    for i in range(cnt+1):
        attack += 2 ** i          
    print(attack)

if __name__ == '__main__':
    main()

Submission status: Accepted

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