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
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(N):
    atk = 0
    if N == 1:
        atk += 1
    else:
        atk += f(N // 2) * 2 + 1
    return atk


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    print(f(N))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H = int(input())

count = 1
Answer = 0

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

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

print(Answer)

Submission status: Accepted

Solution code:
h = int(input())
s = 1
for i in range(h):
  if h <= 1:
    break
  h = h // 2
  s += 1
print((2**s)-1)

Submission status: Accepted

Solution code:
h = int(input())

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

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
H = int(input())

cnt = 0
n = 1

while H != 1:
    cnt += n
    H //= 2
    n *= 2

print(cnt+n)

Submission status: Accepted

Solution code:
from collections import deque
h = int(input())
# stack = deque([h])
# count = 0
# while (len(stack) >= 1):
#     hp = stack.pop()
#     count += 1
#     if (hp == 1):
#         continue
#     else:
#         hp = hp//2
#         stack.append(hp)
#         stack.append(hp)
# print(count)
count = 0
hueru_ryo = 1
while h > 0:
    h = h//2
    count += hueru_ryo
    hueru_ryo *= 2
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

SUM = 0
for i in range(1,cnt+1):
    SUM +=  2**(i-1)

print(SUM)

Submission status: Accepted

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

    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
def main():
    H = int(input())
    print(-1*(1-2**math.floor(math.log2(H)+1)))
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
def count(n):
    p = 0
    for i in range(100):
        if n != 0:
            n = int(n//2)
            p = p+(2**i)
        else:
            break
    return p
print(count(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
power = 0
for i in range(45):
    if 2**i <= h < 2**(i + 1):
        power = i + 1
        break
print(2**power - 1)

Submission status: Accepted

Solution code:
def  atnum(h):
    i=1
    s=1
    while(h>1):
        h=int(h/2)
        i=i*2
        s+=i
    return s
H = int(input())
print(atnum(H))

Submission status: Accepted

Solution code:
n = int(input())
count = 0
num = []
while n != 0:
  num.append(2 ** count)
  count += 1
  n //= 2

print(sum(num))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())
i=1
n=0
s=1
while ( i * 2 <= H):
  i *= 2
  s=s+i
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

i = 0
ans = 1
while h:
    h = h // 2
    i += 1
for _ in range(1, i):
    ans = 2 * ans + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
low = 1
up = 0
while(True):
  up = low * 2
  if low <= h < up:
    break
  low = up
print(up - 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())
count = 1
for i in range(100):
    if H > 1:
        H = int(H/2)
        count += 1
    else:
      break

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

Submission status: Accepted

Solution code:
import math
def Main(H):
    n = math.floor(math.log(H, 2))
    return 2**(n+1)-1

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h = int(input())

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

n = 0
for i in range(1, 40):
    if 2 ** i <= h < 2 ** (i + 1):
        n = 2 ** i
print(n * 2 - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

if h == 1:
    print(1)
else:
    count = 0
    while h >= 2 ** count:
        count += 1
    print(2 ** count - 1)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
H = int(input())

branch_cnt = 1
cnt = 0

while H != 0:
    cnt += branch_cnt
    H = H // 2
    branch_cnt *= 2

print(cnt)

Submission status: Accepted

Solution code:
def caracal(hp):
    return 1 if hp == 1 else ((2 * caracal(int(hp / 2))) + 1)
print(caracal(int(input())))

Submission status: Accepted

Solution code:
H = int(input())
L = [H]
for i in range(1, 10 ** 2 + 1):
    L.append(2**i)
A = sorted(L)
i = A.index(H)

if (A.count(H) == 1):
    print(2 * 2**(i) - 1)
else:
    print(2 * 2**(i + 1) - 1)

Submission status: Accepted

Solution code:
H=int(input())

lo=0
re=1
h=H
while  h>0:
    h=h//2
    lo += re
    re *= 2
print(lo)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math
H = int(input())
x = int(math.log2(H))+1
print((1<<x)-1)

Submission status: Accepted

Solution code:
H = int(input())

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

print(f(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
k = 0
for i in range(48):
    k += 1
    if 2 ** i  > n:
        print(2 ** i - 1)
        break

Submission status: Accepted

Solution code:
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    H = input(int)
    h = H
    count = 0
    while 1 < h:
        h //= 2
        count += 1
    ans = 2 ** count
    temp = 1
    for x in range(count):
        ans += temp
        temp *= 2

    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque

h = int(input())
c = 0
while True:
    if h == 1:
        break
    h = h // 2
    c += 1
ans = 1
for i in range(c):
    ans = ans * 2 + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    h = input_int()

    result = 0
    mon_cnt = 1
    while h != 0:
        result += mon_cnt
        mon_cnt *= 2
        h = (h // 2)

    return result


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

Submission status: Accepted

Solution code:
H = int(input())
counts = 0 
while H > 0:
    H = H//2
    counts += 1
attacks = [2**i for i in range(0, counts)]
print(sum(attacks))

Submission status: Accepted

Solution code:
h = int(input())
count = 0
while h:
    h >>= 1
    count += 1

print(2 ** count -1)

Submission status: Accepted

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

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

print(2 ** i + sum)

Submission status: Accepted

Solution code:
from pprint import pprint
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

H = ri()

def dfs(i):
	if i == 0: return 0
	return 1 + 2 * dfs(i//2)
print(dfs(H))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
def judge(n):
    global num_of_split
    if n==0:
        return
    elif n%2==0:
        num_of_split+=1
        judge(n//2)
    else:
        judge(n-1)

num_of_split=0
H=int(input())
judge(H)
print(pow(2,num_of_split+1)-1)

Submission status: Accepted

Solution code:
h = int(input())

for i in range(40):
    if 2**i <= h < 2**(i+1):
        print(2**(i+1)-1)
        break
    else:
        continue

Submission status: Accepted

Solution code:
h=int(input())
l=[]
i=1
flag=0
while flag!=1:
    l.append(i)
    i*=2
    if h<i:
        flag=1
print(sum(l))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())
for i in range(200):
  if h==1:
    print((2**(i+1))-1)
    exit()
  h=h//2

Submission status: Accepted

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

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

print(f(H))

Submission status: Accepted

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

Submission status: Accepted

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

ans += 2**cnt
print(ans)

Submission status: Accepted

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

print(2 ** d - 1)

Submission status: Accepted

Solution code:
h = int(input())

count=0

while h!=0:
    h = h//2
    count+=1
#階乗
ans=0
for i in range(count):
    ans+=2**i
print(ans)

Submission status: Accepted

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

n = int(math.log2(H))

print(sum([2**i for i in range(n+1)]))

Submission status: Accepted

Solution code:
h = int(input())

for i in range(41):
    if h < 2**i:
        print(2**i-1)
        quit()

Submission status: Accepted

Solution code:
h = int(input())
if h == 1:
    print(1)
    quit()
elif h == 2 or h == 3:
    print(3)
    quit()
for i in range(2,41):
    if h < 2**i:
        print(2**i-1)
        quit()

Submission status: Accepted

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

Submission status: Accepted

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

H = int(input())
print(attack(H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())
x = h
cnt = 0
for i in range(10**12):
  h =h//2
  cnt +=1
  if h<1:
    break
    
ans = 0
for i in range(cnt):
  ans += 2**i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())

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

Submission status: Accepted

Solution code:
H = int(input())

num = 1
cnt = 0

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

Submission status: Accepted

Solution code:
#D
import math
H = int(input())
c = 1
while H>1:
  H = math.floor(H/2)
  c += 1
print(sum([2**i for i in range(c)]))

Submission status: Accepted

Solution code:
h = int(input())

count = 1

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

attack = [0]*count
for i in range(count):
    attack[i] = 2**i

print(sum(attack))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H=int(input())
ans=0
tmp=1
#print("H:",H)
#while H<1:
while H>=1:
    H//=2
    ans+=tmp
    tmp*=2
    #print("H:",H)
print(ans)

Submission status: Accepted

Solution code:
from math import floor

H = int(input())

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

print(f(H))

Submission status: Accepted

Solution code:
n = int(input())
cnt = 0
ans = 1

while n > 1:
  cnt += 1
  ans += 2 ** cnt
  n = n // 2
  
print(ans)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
H = int(input())

ans = 0
exp = 0
while H >0:
    H = H//2
    ans += pow(2,exp)
    exp += 1

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())
f = 0
monster = 1
while h > 1:
    h //= 2 #切り捨て除算
    f += monster
    monster *=2
print(f+monster)

Submission status: Accepted

Solution code:
import sys
import math
def input(): return sys.stdin.readline().rstrip()
def main():
    h=int(input())
    print(2**(int(math.log2(h))+1)-1)

if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(2 ** cnt - 1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

while H > 1:
  if H/2 - H//2 == 0:
    H = H/2
    count += 1
  else:
    H = H//2
    count += 1

print(2**(count) - 1)

Submission status: Accepted

Solution code:
n=int(input())
c=0
p=n
while p!=1:
  p=p//2
  c+=1
print(2**(1+c)-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

H = int(input())


def iterated_power(z: int, n: int, mod=None) -> int:
    """ 繰り返し二乗法でn**kを求める（再帰処理は使わない）
    >>> p = Prime()
    >>> p.iterated_power(3, 10)
    59049
    >>> p.iterated_power(3, 10, 10)
    9
    """
    beta = bin(n)[2:]

    Z, q, t = z, 0, len(beta)
    while beta[t - q - 1] == '0':
        Z = Z * Z
        if mod is not None:
            Z = Z % mod
        q += 1
    result = Z

    for k in range(q + 1, t):
        Z = Z * Z
        if mod is not None:
            Z = Z % mod
        if beta[t - k - 1] == '1':
            result = result * Z
            if mod is not None:
                result = result % mod

    if mod is not None:
        result = result % mod

    return result


ans = iterated_power(2, H.bit_length()) - 1
print(ans)

Submission status: Accepted

Solution code:
h=int(input())
f=0#こうげきかいすう
a = 1#からだ
while h>1:
    h//=2
    #print(h)
    f+=a
    a *=2
print(f+a)

Submission status: Accepted

Solution code:
H = int(input())

i = 1
sm = 1

if H == 1:
    print(1)
    exit()
else:
    while 1:
        H = H // 2
    
        sm += 2**i
        i += 1
    
        if H == 1:
            break

print(sm)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H = INT()

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

cnt = 1

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

Submission status: Accepted

Solution code:
def f(H):
    if H==1:
        return 1
    elif H>1:
        return 2*f(H//2) +1
h=int(input())
print(f(h))

Submission status: Accepted

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

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

t=pow(2,cnt) -1
print(t+2**cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    M=int(input())
    # M = N # Nを変更したくなければ
    log = 0
    while M >= 2:
        M = M // 2
        log += 1
    ans=0
    for i in range(log+1):
        ans+=2**i
    print(ans)


resolve()

Submission status: Accepted

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

while True:
    ans += num
    if H == 1:
        break
    else:
        H //= 2
        num *= 2
print(ans)

Submission status: Accepted

Solution code:
H = int(input())

height = 0 #木の高さ
while H != 1:
    H = H // 2
    height += 1
print(2 ** (height + 1) - 1)

Submission status: Accepted

Solution code:
H = int(input())
def divdivdiv(num):
  cc = 0
  while num:
    num //= 2
    cc += 1
  return cc

print(2 ** divdivdiv(H) - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import floor

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

H = int(input())

ans = attack(H)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 17:15:55 2020

@author: Kanaru Sato
"""

h = int(input())
count = 0

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

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

Submission status: Accepted

Solution code:
def kill(life):
    if life == 1:
        return 1
    elif life > 1:
        return kill(life//2) * 2 + 1
h = int(input())
print(kill(h))

Submission status: Accepted

Solution code:
from math import floor
def kill(life):
    if life in dp.keys():
        return dp[life]
    if life == 1:
        dp[life] = 1
        return 1
    elif life > 1:
        dp[life] = kill(floor(life/2)) * 2 + 1
        return dp[life]
h = int(input())
dp = {}
print(kill(h))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

i = 1
n = 1
while H > 1:
    H = H // 2
    n += 2 ** i
    i += 1
print(n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
int(input())
map(int,input().split())
list(map(int,input().split()))

"""
import math
n=int(input())
ans=int(pow(2,int(math.log2(n)+1))-1)
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

h = n_in()
import math

def do(x):
    if x == 1:
        return 1
    return 1+2*do(math.floor(x/2))

print(do(h))

Submission status: Accepted

Solution code:
import sys

H = int(input())

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

n = 1
ans = 1
dH = H
while True:
    dH = dH // 2
    ans += 2**n
    n += 1
    if dH <= 1:
        break

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h = int(readline())
cnt = 0
if h == 1:
    print(1)
elif h == 2:
    print(3)
else:
    for i in range(h):
        if h < 2 ** i:
            print(cnt)
            exit()
        else:
            cnt += 2 ** i

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def attack(h):
    # 体力hのモンスターを倒す最小回数を返す
    if h == 1:
        return 1
    h //= 2
    return attack(h) * 2 + 1

H = ir()
answer = attack(H)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

while H:
    H = H >> 1
    ans += now
    now = now << 1

print(ans)

Submission status: Accepted

Solution code:
H = int(input())
i = 0
while True:
    if H >= int(pow(2,i)):
        i += 1
    else:
        break
print(int(pow(2,i)-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def atk(H):
    if H == 1:
        return(H)
    else:
        global count
        count += 1
        return(atk(H//2))
count = 0
atk(int(input()))
print(-1*(1-(2**(count+1))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h = int(input())

i = 1
while 1:
    if h<2**i:
        print(2**i-1)
        exit()
    else:
        i+=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H = int(input())

def times(H):
    if H <= 1:
        return H
    else:
        return 1 + 2 * times(H // 2)
      
print(times(H))

Submission status: Accepted

Solution code:
h = int(input())
h_s = bin(h)[2:]
h_s_len = len(h_s)

count_dict = {1: 1}
for i in range(2, h_s_len + 1):
    x = int(h_s[:i], 2)
    count_dict[x] = 1 + 2 * count_dict[x >> 1]

ans = count_dict[h]
print(ans)

Submission status: Accepted

Solution code:
def check_count_func():
    count_dict = {}

    def check_count(x):
        if x in count_dict:
            return count_dict[x]
        
        if x == 1:
            return 1
        
        count_dict[x] = 1 + 2 * check_count(x >> 1)
        return count_dict[x]
    
    return check_count


h = int(input())
h_s = bin(h)[2:]
h_s_len = len(h_s)

f = check_count_func()
for i in range(1, h_s_len):
    x = int(h_s[:i], 2)
    f(x)

ans = f(h)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

h=n0()

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