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: Runtime Error

Solution code:
h = input()
score = 0
fak = 1
while h>1:
	score += fak
	h //= 2
	fak *= 2
print(score+1)

Submission status: Runtime Error

Solution code:
H = map(int, input().split())
enemy = 1
count = 0
while H >= 1:
  count += enemy
  enemy *= 2
  H //= 2
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

H = int(input())
print(H(n))

Submission status: Runtime Error

Solution code:
print 2**len(bin(input()))//4-1

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1E9 + 9;
const int INF = 1<<29; 

long long f(long long x){
    if(x == 1) return 1;
    return f(x/2) * 2 + 1;
}

int main(){
    long long H;
    cin >> H;
    cout << f(H) << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
H = int(input())
x = 2
for i in range(50):
  if x <= H and x*2 > H:
    ans = x*2 - 1
    break
  x = x*2
  
if x == 1:
  ans = 1

print(ans)

Submission status: Runtime Error

Solution code:
H = int(input())
x = 2
for i in range(42):
  if x <= H and x*2 > H:
    ans = x*2 - 1
    break
  x = x*2
  
if x == 1:
  ans = 1

print(ans)

Submission status: Runtime Error

Solution code:
H = int(input())
x = 2
for i in range(41):
  if x <= H and x*2 > H:
    ans = x*2 - 1
    break
  x = x*2
  
if x == 1:
  ans = 1

print(ans)

Submission status: Runtime Error

Solution code:
H = int(input())
x = 2
for i in range(40):
  if x <= H and x*2 > H:
    ans = x*2 - 1
    break
  x = x*2
  
if x == 1:
  ans = 1

print(ans)

Submission status: Runtime Error

Solution code:
H = int(input())
x = 2
for i in range(40):
  if x < H and x*2 >= H:
    ans = x*2 - 1
    break
  x = x*2

print(ans)

Submission status: Runtime Error

Solution code:
H = int(input())
x = 2
for i in range(40):
  if x < H and x*2 > H:
    ans = x*2 - 1
    break
  x = x*2
    
print(ans)

Submission status: Runtime Error

Solution code:
h = int(input())

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

Submission status: Runtime Error

Solution code:
a=int,input()
count=0
s=1
while True:
  if a!=1:
    a=a//2
    count+=1
    s+=2**count
  else:
    s+=2**count

Submission status: Runtime Error

Solution code:
h = int(input())

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

print(count(h))

Submission status: Runtime Error

Solution code:
h = int(input())
beki = 0
ans = 0

while h > 1:
    h = h // 2
    beki+=1
    ans += 2**beki
    
print(

Submission status: Runtime Error

Solution code:
h = int(input())

log = {'1': 1 , '2': 3, '3': 3, '4': 7 }

i = 1
while i <= h:
  if str(i) in log:
    # print(log[str(i)])
  else:
    n = i // 2
    log.setdefault(str(i), log[str(n)]*2+1)
    # print(log[str(i)])
  i=i+1
print(log[h])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np


H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
a, b = np.array(AB, dtype=np.int64).reshape(N, 2).T

d = np.zeros(H + 1, dtype=np.int64)

for hp in range(1, H + 1):
    c = d[np.maximum(hp - a, 0)] + b
    d[hp] = np.amin(c)
    print(hp, np.amin(c))

print(d[H])

Submission status: Runtime Error

Solution code:
import math
import sys
sys.setrecursionlimit(100000)
h = int(input())
#再帰で解く
def f(n):
    if(n == 1):
        return 1  
    a =  math.floor(f(n/2))
    return 2*a+1

    
print(f(h))

Submission status: Runtime Error

Solution code:
h = int(input())
li = []
#再帰で解く
def f(n):
    if(n == 1):
        return 1   
    return 2*int(f(n/2))+1
print(f(h))

Submission status: Runtime Error

Solution code:
h = int(input())
li = []


"""
li.append(h)
c=1
while(h >  1):
    h= int(h/2)
    for i in range(2**c):   #計算量がクソ多くなる
        li.append(h)
    c += 1

#print(li)
print(len(li))
"""
c=0

def f(n):
    #global c
    #c+=1
    if(n == 1):
        return 1
    else:
        return 2*int(f(n/2))+1

print(f(h))

Submission status: Runtime Error

Solution code:
import math

h = int(input())
len = int(math.log2(h) + 1)
ans = 1<<len
print(ans-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

    print(2**l * 2 -1)

Submission status: Runtime Error

Solution code:
import math 
 
h=int(input())
x =math.floor(math.log2(h))
print( sum([2**y for y in range(x+1)]))

Submission status: Runtime Error

Solution code:
H = int(input())

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

print(count)

Submission status: Runtime Error

Solution code:
H = int(input())
cnt = H
B = [H]

if H == 1:
    ans == 10000000001
else:
    for i in range(100000000000):
        cnt = cnt//2
        B.append(cnt)
        if cnt == 1:
            break

C =[1]
for i in range(1,1001):
    C.append(C[i-1]*2)

if ans == 10000000001:
    print('0')
else:
    ans= 0
    for i in range(len(B)):
        ans +=C[i]
print(ans)

Submission status: Runtime Error

Solution code:
H = int(input())
ans = 0
if H != 1 and H % 2 == 1:
    H = H+1
elif H == 1:
    print(1)
 
 
print((pow(2,(H//2)-1)

Submission status: Runtime Error

Solution code:
H = int(input())

cnt = H
B = [H]
if H == 1:
    print('0')
else:
    for i in range(100000000000):
    cnt = cnt//2
    B.append(cnt)
    if cnt == 1:
        break
    C =[1]
    for i in range(1,1001):
        C.append(C[i-1]*2)
    ans= 0
    for i in range(len(B)):
        ans +=C[i]
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

# i = format(n, 'b')[::-1].find('1')
ans = 0
k = 1
while True:
  n //=2
  ans += k
  k *= 2
  if n =< 1:
    break

print(ans+k)

Submission status: Runtime Error

Solution code:
h,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
 
dp=[0]*h
for i in range(h):
    _min = 10**10
    for g in range(n):
        if i>=ab[g][0]:
            _min = min(ab[g][1]+dp[i-ab[g][0]], _min)
        else:
            _min = min(ab[g][1], _min)
    dp[i]=_min
print(dp[-1])

Submission status: Runtime Error

Solution code:
H = int(input())

g = int(H / 2)
if g == 0:
    print(1)
else:
    n = 0
    while True:
        if 2 ** (n + 1) < H:
            n += 1
        elif 2 ** (n + 1) >= H:
            break
    for i in range(n):
        ans = ans + 2 ** i
print(ans + 1)

Submission status: Runtime Error

Solution code:
for i in range(10000):
    if n > 2**i:
        pass
    elif n == 1:
        print(1)
    elif n == 2**i:
        print(4*(2**(i)//2)-1)
        break
    else:
        print(4*(2**(i-1)//2)-1)
        break

Submission status: Runtime Error

Solution code:
import math

n = int(input())

print(n)
count = 0
while(true):
  if(n==1):
    print(1)
    break
  elif(n==2):
    print(2*count)
    break
  else:
    n=math.floor(n/2)
    count += 1

Submission status: Runtime Error

Solution code:
H = int(input())

a = 2
n = 0

while H // 2 > 1:
  H = H // 2
  X = [2 ** n for i in range(0,n)]
  n = n + 1
else:
  n = n + 1
  X.append(2**n)

print(sum(X)+1)

Submission status: Runtime Error

Solution code:
h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
# ans=1
# for i in range(n):
#     ans+=a[i][0]
M=10**12
dp=[[M for i in range(max(h+10010,2*h+2))] for j in range(n+1)]
for i in range(n+1):
    dp[i][0]=0
for i in range(n):
    for j in range(max(h+10010,2*h+2)):
        if j<a[i][0]:
            dp[i+1][j]=dp[i][j]
        elif dp[i+1][j-a[i][0]]<M and dp[i][j]<M:
            dp[i+1][j]=min(dp[i][j],dp[i+1][j-a[i][0]]+a[i][1])
        elif dp[i+1][j-a[i][0]]<M:
            dp[i+1][j]=dp[i+1][j-a[i][0]]+a[i][1]
        elif dp[i][j]<M:
            dp[i+1][j]=dp[i][j]
# for i in range(n+1):
#     print(dp[i])
for i in range(h,max(h+10010,2*h+2)):
    if dp[n][i]<M:
        print(dp[n][i])
        exit()

Submission status: Runtime Error

Solution code:
h,n = map(int,input().split())

x = []
y = []

for i in range(n):
    a,b = map(int,input().split())
    x.append(a)
    y.append(b)

def knapsack(N,W,weight,value):
  inf=float("inf")
  dp=[[inf for i in range(W+1)] for j in range(N+1)]
  for i in range(W+1): dp[0][i]=inf

  for i in range(N):
    for w in range(W+1):
        m = dp[i][w]
        p = value[i]
        q = weight[i]
        while w >= q:
            if w - q >= 0:
                m=min(dp[i][w-q]+p,m)
            p += value[i]
            q += weight[i]
        m=min(dp[i][w-q]+p,m,p)
        dp[i+1][w] = m
  return dp[N][W]

k = knapsack(n,h,x,y)
print(k)

Submission status: Runtime Error

Solution code:
import math 

h=int(input())
x =math.ceil(math.log2(h))
print( sum([2**y for y in range(x+1)]))

Submission status: Runtime Error

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

# 入力
temp=int(input())
H_List=[temp]

result=0
i=0

while sum(H_List)>0:
    # モンスターの体力が 1 なら、そのモンスターの体力は 0になる
    if H_List[i]==1:
        H_List[i]=0
    # モンスターの体力が X>1なら、そのモンスターは消滅し、体力が ⌊X/2⌋ のモンスターが新たに 2 体現れる
    elif H_List[i]>1:
        temp=H_List[i]/2
        H_List.append(temp)
        H_List.append(temp)
        H_List[i]=0
    result+=1
    i+=1



print(result)

Submission status: Runtime Error

Solution code:
import bisect

n=int(input())
lst=[1]
lst2=[1]
for i in range(1,41):
  lst.append(2**i)
  lst2.append(lst2[i-1]+lst[i])
  
ind=bisect_left(lst,n)
print(lst2[ind])

Submission status: Runtime Error

Solution code:
"""
if a monster is not attacked, it doesn't do anything, so we can
deal with each living monster as a separate problem that takes
a certain number of moves to kill it and all of its offspring.
when x is not 1,
num(x) = 2*num(floor(x/2))+1
(because it took one move to kill it, and there will be two offspring)
and when x is 2 or 3,
num(x) = 3
so we can do some recursion, or memoization, or tabulation
"""

from math import floor


def get_num_attacks(H):
  if H>3:
    return 2*get_num_attacks(floor(H/2))+1
  if H==2 or H==3:
    return 3
  if H==1
    return 1


if __name__ == "__main__":
  H = int(input())
  print(get_num_attacks(H))

Submission status: Runtime Error

Solution code:
H=int(input())

S=H//2 +1

print(2**S-1)

Submission status: Runtime Error

Solution code:
import math
a = []
b = []
toki = []
h, n = map(int, input().split())
for i in range(n):
  ai, bi =  map(float, input().split())
  toki.append((ai, bi))

def yeah(hp, toki):
  mp = 0
  dps = 0
  kou = 0
  for ai, bi in toki:
    t = ai
    if (hp - ai) <= 0:
      t = hp
    dps2 = float(t/bi)
    if dps <= dps2:
      dps = dps2
      mp = bi
      kou = t
  return (hp-kou, mp)
mp = 0
zan = h
while True:
  zan, mp2 = yeah(zan, toki)
  mp += mp2
  if zan <=0:
    break
print(int(mp))

Submission status: Runtime Error

Solution code:
H = int(input())
ans = 0
if H != 1 and H % 2 == 1:
    H = H+1
elif H == 1:
    print(1)


print((pow(2,H//2)-1))

Submission status: Runtime Error

Solution code:
H = int(input())
cnt = 0
n = math.floor(math.log2(H))
ans = 0
for i in range(n+1):
    cnt += int(math.pow(2,i))
print(cnt)

Submission status: Runtime Error

Solution code:
H = int(input())

cnt = H
B = [H]
for i in range(1000):
    cnt = cnt//2
    B.append(cnt)
    if cnt == 1:
        break

C =[1]
for i in range(1,100):
    C.append(C[i-1]*2)

ans= 0
for i in range(len(B)):
    ans +=C[i]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
mport numpy as np
import math

H = input()
H_bar=int(H)
counter=0
bunki=0

while H_bar!=1:
 H_bar=math.floor(H_bar/2)
 bunki=bunki+2**counter
 counter=counter+1
  
Sum=bunki+2**counter
print(Sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def a(H):
    global ans
    global dic
    if H // 2 in dic:
        add = 2 * ans + 1
        ans = add
        dic[H] = add
    else:
        a(H//2)
        a(H//2)

H = int(input())
dic = {}
dic[1] = 1
ans = 1
a(H)
print(ans)

Submission status: Runtime Error

Solution code:

def a(H):
    global ans
    global dic
    if H // 2 in dic:
        add = 2 * ans + 1
        ans = add
        dic[H] = add
    else:
        a(H//2)
        a(H//2)



H = int(input())
dic = {}
dic[1] = 1
ans = 1
a(H)
print(ans)

Submission status: Runtime Error

Solution code:
from functools import lru_cache
h = int(input())
count = 0

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

@lru_cache(maxsize=100000)
def f(n):
    if n < 1:
        return 3
    else:
        return f(n - 1)*2 + 1

print(f(count))

Submission status: Runtime Error

Solution code:
H = list(map(int, input().split()))
count = 0

def increase(a, b):
    a.append(b//2)
    a.append(b//2)
    del a[0]
    
for _ in range(10000):
    h = H[0]
    print('h:', H[0])
    count+=1
    if h > 1:
        increase(H, h)
    else:
        del H[0]
    if len(H) == 0: break
    print(H)
        
print(count)

Submission status: Runtime Error

Solution code:
h = int(input())
x = "1"*(h//2 + 1)
print(int(x,2))

Submission status: Runtime Error

Solution code:
#python3
def main():
    h = int(input())
    n = h//2 + 1
    s = ''.join(['1']*n) 
    ans = int(s, 2)
    print(ans)
main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
h = int(input())
if h > 1:
	h = h / 2
	ans = 2 ** (h + 1) -1
	print(int(ans))
else:
	print(1)

Submission status: Runtime Error

Solution code:
h = int(input())
if h == 0:
  print(0)
  quit()
def waruni(i):
  if i == 2 or i == 3:
    return 3
  else:        
    r = waruni(i//2) * 2 + 1
    return r
rus = waruni(h)
print(rus)
# I love kemofure

Submission status: Runtime Error

Solution code:
h = int(input())
n = h//2
x = "0b1"+("0"*(n+1))
# print(x)
# print((int(x,2)))
print(int((1-(int(x,2)))/(1-2)))
#print(int((1-2**(n+1))/(1-2)))

Submission status: Runtime Error

Solution code:
H = int(input())
M = []
M.append(H)

A = 0

if len(H) == 0:
  print(A)
else:
  if H[0] == 1:
    M.pop(H[0])
    A += 1
  else:
    H[0] = H[0] / 2
    A.append(H[0]/2)
    A += 1

Submission status: Runtime Error

Solution code:
h = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))

ans_L = [0] * (10**12 + 1)

i = 0
ans_L = [1]
while h!=1:
    h = h//2
    i += 1
    ans_L.append(2**i)

print(sum(ans_L))

Submission status: Runtime Error

Solution code:
h = int(input())
def waruni(i):
  if i == 2 or i == 3:
    return 3
  else:        
    r = waruni(i//2) * 2 + 1
    return r
rus = waruni(h)
print(rus)
# I love kemofure

Submission status: Runtime Error

Solution code:
 = int(input())

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

print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
H = int(input())
#H = 1000000000000

#K = 1
#N = 3
#An = [4,1,5]

import numpy as np

cnt=0
for i in range(1000000):
    if H<2**(i+1):
        break
    else:
        cnt+=1
        
#import math

if cnt ==0:
    break_cnt==0
else:    
    break_cnt = np.sum([2**i for i in range(cnt)])
    
kill_cnt = 2**cnt 

print(kill_cnt + break_cnt)

Submission status: Runtime Error

Solution code:
h = map(int, input().split())
print(2 ** h - 1)

Submission status: Runtime Error

Solution code:

def split_monster(n, count):
  count += 1
  if n == 1:
    return count
  count = split_monster(n/2, count)
  count = split_monster(n/2, count)
  return count

n = int(input())
count = 0
count = split_monster(n, count)
  
print(count)

Submission status: Runtime Error

Solution code:
H = int(input())
#H = 1000000000000

#K = 1
#N = 3
#An = [4,1,5]

import numpy as np

cnt=0
for i in range(1000):
    if H<2**(i+1):
        break
    else:
        cnt+=1
        
import math

if cnt ==0:
    break_cnt==0
else:    
    break_cnt = np.sum([2**i for i in range(cnt)])
    
kill_cnt = 2**cnt 

print(kill_cnt + break_cnt)

Submission status: Runtime Error

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

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

print(helper(H))

Submission status: Runtime Error

Solution code:
# D
def touhi(a,r,n):
    return a*(pow(r, n) - 1)//(r-1)
  
H = int(input()) 
n = math.floor(math.log2(H))+1
print(touhi(a=1, r=2, n=n))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
def main():
    h = int(input())
    cnt = 0
    ans = 0
    tmp = 1
    a = int(math.log2(h))
    cnt = 2 **a
    ans = (1-2**a)//(1-2)
    print(ans+cnt)
    # while True:
    #     h //=2
    #
    #     cnt += tmp
    #     tmp *= 2
    #     if h==1:
    #         break
    #
    # print(cnt+tmp)
if __name__=='__main__':
    main()

Submission status: Runtime Error

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

def helper(x):
  if x == 1:
    global count
    count += 1
    return
  count += 1
  helper(x/2)
  helper(x/2)

helper(H)
print(count)

Submission status: Runtime Error

Solution code:
H = int(input())

if H%2==1:
  H = H-1

from math import log2
deep = int(log2(H))+1
ans = 0
for d in range(0,deep):
  ans += 2**d

print(ans)

Submission status: Runtime Error

Solution code:
import math
h = int(input())
i = int(math.ceil(h/2))
print(int("1"*(i+1), 2))

Submission status: Runtime Error

Solution code:
h=int(input())

a=1
b=1
ans=0s
for i in range(1,h+1):
       if i==b:
              ans+=b
              b=b*2
              
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
t=n//2
def pow_r(x, n):
    if n == 0:  
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2)
    else:
        return x * pow_r(x ** 2, (n - 1) // 2)
if(n%2==0):
  print(pow_r(2,t+1)-1)
else:
  print(pow_k(2,t)-1)

Submission status: Runtime Error

Solution code:
import math

n=int(input())
x=math.ceil(math.log2(n))
print(int(math.pow(2,x+1)-1))

Submission status: Runtime Error

Solution code:
h, n = map(int, input().split())

m = [i for i in input().split()]

result = 0

for i in m:
    result += int(i)

if result >= h:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
map<ll,ll> mp;
ll dp(ll h){
	if(h==1) {
		return 1;
	}
	return 2*dp(h/2)+1;
}
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	ll h;
	cin>>h;
	cout<<dp(h)<<endl;



	return 0;
}

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
N = list(map(int,input().split()))
N.sort()
for i in range(b):
    if N:
        N.pop()
print(sum(N))

Submission status: Runtime Error

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# import re
# import array
# import copy
# import functools
# import operator

import math
# import string
import fractions
# from fractions import Fraction
from fractions import gcd

# import collections
# import itertools
# import bisect

# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue

# from itertools import accumulate

# from collections import deque
# from collections import Counter

from operator import mul
from functools import reduce

# def lcm(n,m):
#     return int(n*m/gcd(n,m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


# import random
# import time


def main():
    h = int(input().strip())
    t_height = math.log2(h)
    eprint("t_height ", end=": ")
    eprint(math.ceil(t_height))
    t_height = math.ceil(t_height)
    print(2**(t_height) - 1)
    return


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)

h = int(input())
h_dash = h if h % 2 == 0 else h - 1


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


print(f(h_dash))

Submission status: Runtime Error

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# import re
# import array
# import copy
# import functools
# import operator

# import math
# import string
import fractions
# from fractions import Fraction
from fractions import gcd

# import collections
# import itertools
# import bisect

# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue

# from itertools import accumulate

# from collections import deque
# from collections import Counter

from operator import mul
from functools import reduce

# def lcm(n,m):
#     return int(n*m/gcd(n,m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


# import random
# import time


def main():
    h = int(input().strip())
    print(2**(h - 1) - 1)
    return


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

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

c = 0

def attack(h):
  if h == 1:
    c += 1
    return c
  else:
    return attack(floor(2/h)) + attack(floor(2/h))
  
print(attack(h))

Submission status: Runtime Error

Solution code:
n=int(input())

def count_attack(hp):
    count = 0
    if hp == 2 or hp == 3:
        return 3
    else:
        # calculate new hp
        count += 1
        hp_child = hp //2
        count += 2 * count_attack(hp_child)
        return count

print(count_attack(n))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(20000)


class Dp:

    def __init__(self, size):
        self.size = size
        self.array = [0] * (size+1)

    def calc(self, n):
        if n == 1:
            return 1
        if self.array[n] != 0:
            return self.array[n]
        self.array[n] = self.calc(n//2) * 2 + 1
        return self.array[n]


def main():
    h = int(input())
    dp = Dp(h)
    result = dp.calc(h)
    print(result)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
h = int(input())
x = int(math.log2(h))
s = 0
for i in range(x+1):
    s += 2**i
print(s)

Submission status: Runtime Error

Solution code:
import math

def main():
    h = int(input())
    n = math.floor(math.log2(h))
    print(2**(n+1)-1)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10000)


class Dp:

    def __init__(self, size):
        self.size = size
        self.array = [0] * (size+1)

    def calc(self, n):
        if n == 1:
            return 1
        if self.array[n] != 0:
            return self.array[n]
        self.array[n] = self.calc(n//2) * 2 + 1
        return self.array[n]


def main():
    h = int(input())
    dp = Dp(h)
    result = dp.calc(h)
    print(result)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
H = int(input())
A = math.log(H, 2)

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

print(ans)

Submission status: Runtime Error

Solution code:
from math import log2, floor

H = int(input())

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

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**20)


class Dp:

    def __init__(self, size):
        self.size = size
        self.array = [0] * (size+1)

    def calc(self, n):
        if n == 1:
            return 1
        if self.array[n] != 0:
            return self.array[n]
        self.array[n] = self.calc(n//2) * 2 + 1
        return self.array[n]


def main():
    h = int(input())
    dp = Dp(h)
    result = dp.calc(h)
    print(result)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
class Dp:

    def __init__(self, size):
        self.size = size
        self.array = [0] * (size+1)

    def calc(self, n):
        if n == 1:
            return 1
        if self.array[n] != 0:
            return self.array[n]
        self.array[n] = self.calc(n//2) * 2 + 1
        return self.array[n]


def main():
    h = int(input())
    dp = Dp(h)
    result = dp.calc(h)
    print(result)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
H = int(input())

bin_h = str(bin(H)[2:])
len_h = len(bin_h)
ans = 2 ** len_h - 1

if bin_h[1] == 1:
  ans += 2 ** (len_h - 1)
  
print(ans)

Submission status: Runtime Error

Solution code:
import math
h = int(input())
ans = 0
num = 0
for i in range(41,0,-1):
    if 2**i <= h:
        num = 2**i
        rep = i
        # print(i)
        break
for i in range(rep+1):
    ans += 2**i
# print(num)
print(ans)

Submission status: Runtime Error

Solution code:
H = int(input())

def solve(h):
    ans = 0
    if h==2 or h==3:
        ans = 3
    else:
        ans += 1
        ans += 2 * solve(h//2)
    return ans

ans = solve(H)
print(ans)

Submission status: Runtime Error

Solution code:
    H = int(input())

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

Submission status: Runtime Error

Solution code:
from math import log2

H = int(input())

print(sum(
    2 ** i
    for i in range(int(log2(H)) + 1)
))

Submission status: Runtime Error

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

print(pow(2, cnt) - 1)

Submission status: Runtime Error

Solution code:
import sys
from collections import deque, defaultdict
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush
from math import pi, inf
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()