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: Wrong Answer

Solution code:
start = int(input())

all_monsters = [start]


turn = 0

while len(all_monsters) != 0:
    if all_monsters[0] == 1:
        del all_monsters[0]
        turn += 1
    else:
        if all_monsters[0] % 2 == 0:
            tmp = int(all_monsters[0] / 2)
            del all_monsters[0]
            all_monsters.append(tmp)
            all_monsters.append(tmp)
        else:
            tmp = int((all_monsters[0] + 1) / 2)
            del all_monsters[0]
            all_monsters.append(tmp)
            all_monsters.append(tmp)
        turn += 1
            
print(turn)

Submission status: Wrong Answer

Solution code:
H = int(input())

cnt = 0
while H > 3:
    H = H//2
    cnt += 1
ans = 0
for i in range(cnt):
    ans += 2**i
print(int(((2**cnt)*3)+ans))

Submission status: Wrong Answer

Solution code:
H = int(input())

# INF = float('inf')

# dp = [INF for i in range(H+10)]
# dp[0] = 0
# dp[1] = 1

# for i in range(1, H+1):

#     dp[i+1] = min(dp[i+1], dp[(i+1)//2] * 2 + 1)

# print(dp[H])

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

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

Submission status: Wrong Answer

Solution code:
import math
h = int(input())
for i in range(h):
    if h == 0:
        print(2**(i) - 1)
        break
    h = math.floor(h/2)

Submission status: Wrong Answer

Solution code:
import math

h = int(input())

def sum(list,k):#最初からk個までの和
    s = 0
    for i in range(len(list)-k):
        s = s+ list[i]
    return s

#print(h*1.0)

x = math.ceil(math.log2(h*1.0))

#print(x)



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

Submission status: Wrong Answer

Solution code:
H = int(input())

cnt = 0
while H > 3:
    H = H//2
    cnt += 1
print(H)
print(cnt)
ans = 0
for i in range(cnt):
    ans += 2**i
print(int(((2**cnt)*3)+ans))

Submission status: Wrong Answer

Solution code:
import math


h = int(input())

n = 0
while True:

    h = math.floor(h/2)
    if h <= 1:
        n += 1
        break
    else:
        n += 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
H = int(input())
import numpy as np
from math import ceil

K = ceil(np.log2(H))
L = 2 ** (K + 1) - 1

print(L)

Submission status: Wrong Answer

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

if n % 2 == 1:
    n -= 1

if n % 2 == 0:
    for i in range(int(n/2)):
        a = 2*a + 1

print(a)

Submission status: Wrong Answer

Solution code:
i=int(input())
nest=1
a=0
p=i
while True:
  nest+=1
  p=p//2
  if p==1:
    break
for k in range(nest):
  a+=2^k
print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
h = int(input())

dp = [0, 1]

for i in range(2, 100001):
    x = 1 + 2 * dp[i // 2]
    dp.append(x)


if h < 100001:
    print(dp[h])



else:
    l = []
    y = h
    while y >= 100001:
        l = [x] + l
        y = y// 2
    ans = 1 + 2 * dp[l[0] // 2]
    if len(l) > 1:
        for i in range(len(l) - 1):
            ans = 1 + 2 * ans
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
H = int(input())

# nが0になるまで何回割れるか
def divCount(n, cnt = 0):
    if n <= 1:
        return cnt
    return divCount(n / 2, cnt + 1)

attackCount = 0
for i in range(0, divCount(H)+1):
    attackCount += pow(2, i)

print(attackCount)

Submission status: Wrong Answer

Solution code:
H=int(input())
h=H//2
a=1
b=1
c=1
for i in range(H):
    if h==1:
        break
    if h==0:
        break
    h=h//2
    a+=1
for i in range(a):
    c=2*c
    b=b+c
print(b)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def solve(H: int):

    if H == 1:
        print("1")
        return

    i = 1
    m = 1
    flag = True
    while True:
        if H % 2 != 0:
            flag = False
        H = -(H // 2)
        i *= 2
        m *= 2
        if H == 1:
            if flag:
                i += m
            i -=1
            break
    print(i)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    solve(H)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
H = int(input())

cnt = 1
ans = 1
while True:
    if H // 2 > 1:
        H //= 2
        ans += 2 ** cnt
        cnt += 1
    else:
        ans += 2 ** cnt
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[2**i for i in range(50)]

for i in range(50):
    if n<a[i]:
        x=i-1
        break
    if n==a[i]:
        x=i

print(4*(2**(x-1))-1)

Submission status: Wrong Answer

Solution code:
h = int(input())

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

Submission status: Wrong Answer

Solution code:
from math import log

h=int(input())
a=int(log(h,2)+0.0001)
print(pow(2,a+1)-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
h = int(input())
ans = 0
a_l = [h]
if h == 1:
    print(1)
else:
    while True:
        ans += 1
        if a_l[0] == 1:
            if len(a_l) == 1:
                break
        else:
            a_l.append(a_l[0]//2)
            a_l.append(a_l[0]//2)
        a_l = a_l[1:]
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
H=int(input())

opt=[1]
while opt[-1]<=10**12:
    opt.append(opt[-1]*2+1)

count=0
temp=1
while temp<H:
    temp*=2
    count+=1
if count>39:
    print(opt[-1])
else:
    print(opt[count])

Submission status: Wrong Answer

Solution code:
def main():
    import math
    H = int(input())
    if H == 1:
        print(1)
    else:
        if H%2 != 0:
            H += 1
        count = int(math.log(H,2))
        ans = 0
        for i in range(count):
            ans += 2**(i)
            if i == count-1:
                ans += 2**(i+1)
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

while True:
  h = h//2
  count += 1
  if h <= 1:
    break
    
print(2**(count+1)-1)

Submission status: Wrong Answer

Solution code:
h = int(input())
ret = 1
for i in range(10**6):
    h = h//2
    if h//2 < 1:
        ret += 1
        break
    else:
        ret += 1

print(sum([2**i for i in range(ret)]))

Submission status: Wrong Answer

Solution code:
def main():
    import math
    H = int(input())
    if H%2 != 0:
        H += 1
    count = int(math.log(H,2))
    ans = 0
    for i in range(count):
        ans += 2**(i)
        if i == count-1:
            ans += 2**(i+1)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

h=ii()
num = 1
cnt=0
while h >0:
    if h >1:
        h = ceil(h/2)
        cnt+=num
        num*=2
    else:
        h-=1
        cnt+=num

print(cnt)

Submission status: Wrong Answer

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

print(2 ** math.ceil(math.log(h+1,2)) - 1)

Submission status: Wrong Answer

Solution code:
h = int(input())

lhb = len(format(h, "b"))
print(2 ** lhb  - 1 + lhb)

Submission status: Wrong Answer

Solution code:
# cook your dish here
from math import log2
n=int(input())
k=round(log2(n))
if int(k)==k:
    print(pow(2,k+1)-1)
else:
    print(pow(2,k)-1)

Submission status: Wrong Answer

Solution code:
h=int(input())

out=0
c=0

while h>1:
    h=h//2 if h%2==0 else (h+1)//2
    out+=2**c
    c+=1

out+=2**c if h!=1 else 0

print(out)

Submission status: Wrong Answer

Solution code:
h = int(input())

lhb = len(format(h, "b"))
print(2 * lhb  - 1)

Submission status: Wrong Answer

Solution code:
h = int(input())

n = 0
while 2**n < h:
    n += 1

print(2**n-1)

Submission status: Wrong Answer

Solution code:
n=int(input())

for i in range(50):
    if n<2**i:
        break
print(i)

out=0
for k in range(i):
    out+=2**k

print(out)

Submission status: Wrong Answer

Solution code:
h=int(input())

out=0
c=0

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

out+=2**c if h!=1 else 0

print(out)

Submission status: Wrong Answer

Solution code:
H = int(input())
K = 0
for ii in range(40):
  if (H>=2**ii) & (H<=2**(ii+1)):
    K= ii
    break
print(2**(K+1)-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
H = int(input())
n = 1
h = H
while True:
    n *= 2
    h = h//2
    if h <= 1:
        break
print(n*2-1)

Submission status: Wrong Answer

Solution code:
from math import ceil
h=int(input())
cnt=0
while h!=1:
    cnt +=1
    h=ceil(h/2)
print(2**cnt-1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
n = int(stdin.readline().rstrip())
i = 0
while True:
    if 2**i >= n:
        break
    i += 1
point = 0
for j in range(i):
    point += 2**j
print(point)

Submission status: Wrong Answer

Solution code:
H = int(input())
num = 1
ans = 1
for _ in range(50):
    H //= 2
    num *= 2
    ans += num
    if H == 1:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())

cnt = 1
for i in range(10**12):
  h = h//2
  n = 2**(i+1)
  cnt += n
  if h == 1:
    print(cnt)
    exit()

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
E = [H]
cnt = 0
while E[len(E)-1] != 0:
    if E[cnt]==1:
        E[cnt]=0
    else:
        E.append(int(E[cnt]/2))
        E.append(int(E[cnt]/2))
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
monster = deque()
monster.append(int(input()))
count = 0
while monster:
    n = monster.pop()
    if n != 1:
        n = n // 2
        monster.append(n)
        monster.append(n)
        count += 1
    else:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

ans = 0
l = [H]
while len(l) > 0:
  ans += 1
  if l[0] == 1: del l[0]
  else:
    l = [l[0] // 2] + [l[0] // 2] + l[1:]

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
l = [int(input())]
c = 0

while l:
  
  if l[0] == 1:
    l.remove(1)
  else:
    x = math.floor(l[0] / 2)
    l.remove(l[0])
    l.append(x)
    l.append(x)
  c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
h=int(input())
a=[]
while h>=1:
    a.append(h)
    h//2
count=0
for i in a:
    while a[i]>=1:
        count+=1
        a[i]//2
print(count)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
monster = [h]
ans = 0
while len(monster) >= 1:
  for index,m in enumerate(monster):
    if m == 1:
      ans += 1
      del monster[index]
    else:
      ans += 1
      del monster[index]
      new = m // 2
      monster.append(new)
      monster.append(new)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
ans = 0
while H > 0:
    if H == 1:
        ans += 1
    else:
        e = H // 2
        ans += e
        H -= 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = [int(input())]
 
ans = 0
while len(H):
  ans += 1
  m = H.pop(0)
  if m == 1:
    continue
  else:
    H = H + [m//2, m//2]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
q, r = divmod(H, 2)
i = 1
while q != 1:
    q //= 2
    i += 1
ans = 0
for j in range(i + 1):
    ans += 2 ** j
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
list = []
list.append(h)
count = 0
while list.count(1) != len(list) :
    max_index = list.index(max(list))
    list[max_index] //= 2
    list.append(list[max_index])
    count += 1
print(count+len(list))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    h = int(input())
    c = 0
    total = 0
    while True:
        total += 2**c
        h = h//2
        if h == 1:
            c += 1
            total += 2**c
            break
        c += 1
    print(total)
resolve()

Submission status: Time Limit Exceeded

Solution code:
import queue

H = int(input())

q = queue.Queue()
q.put(H)

c=0
while not q.empty():
    x = q.get()
    x = x // 2
    if x > 0:
        q.put(x)
        q.put(x)
    c+=1

print(c)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
m = []
ans = 0
m.append(h)
while True:
  if m[0] == 1:
    del m[0]
    ans += 1
  elif m[0] > 1:
    m.append(m[0]//2)
    m.append(m[0]//2)
    del m[0]
    ans += 1
  if m == []:
    print(ans)
    exit()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
i=0
while(1):
    n//=2
    i+=1
    if n==1:
        break
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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
a = [H]
i = 0
while a != [1]*len(a):
    a = a[1:]

    a += [int(H / 2) for i in range(2)]
    H = a[0]

    i += 1
print(i+sum(a))

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
l = [H]
c = 0
while l:
    h = l.pop()
    c += 1
    if h == 1:
        pass
    else:
        l.append(h//2)
        l.append(h//2)
print(c)

Submission status: Time Limit Exceeded

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

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

    print(battle(H))

    return
  
resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    H = int(input())
    depth = 0
    monster = [2 ** depth]
    depth += 1

    while True:
        monster.append(2 ** depth)

        if H % 2 == 1:
            H = (H-1)/2
        else:
            H = H / 2
        depth += 1

        if H == 1:
            break

    print(sum(monster))

    return


resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
m = 1
at = 0
while True:
    at += m
    H //= 2
    m *= 2
    if H == 1:
        at += m
        print(at)
        exit()

Submission status: Time Limit Exceeded

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

count = 0
while len(monster) > 0:
    p = monster.pop()
    if p == 1:
        count += 1
    else:
        count += 1
        monster.append(p//2)
        monster.append(p//2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
m = [h]
ans = 0
while(sum(m)>0):
    for i in range(len(m)):
        while m[i]>0:
            if m[i]==1:
                ans += 1
                m[i]=0
            elif m[i]>1:
                ans+= 1
                m[i]/=2
                m.append(m[i])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
enemies = [int(input())]

def attack(N):
    return [N // 2] * 2

times = 0
while len(enemies) > 0:
    tmp = enemies.pop(-1)
    times += 1
    if tmp >= 2:
        enemies += attack(tmp)

print(times)

Submission status: Time Limit Exceeded

Solution code:
def f(h):
    #print(f"h = {h}")
    count = 0
    while len(h):
        n = h.count(1)
        if n:
            h.pop(h.index(1))
            count += 1
        if len(h) and h[0] > 1:
            new = h.pop(0) // 2
            h.append(new)
            h.append(new)
            count += 1
    return count

h = [int(input())]
print(f(h))

Submission status: Time Limit Exceeded

Solution code:
# ABC 153 D
H = int(input())
def del_jug(L):
    return set(L) !=set([1])

cnt=0
L = [H]
while  del_jug(L):
    
    H = int(L[-1]/2)
    L.append(H)
    L.append(H)
    L =sorted(L)
    
    L.pop(-1)
    
    cnt+=1
    
print(cnt+len(L))

Submission status: Time Limit Exceeded

Solution code:
H=int(input())
count=0
m=1
while H:
  if H==1:
    count+=m
  else:
    m*=2
    H=int(H/2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

def attack(hp_list_old, count_attack_old):
    hp_list_new = []
    count_attack_new = count_attack_old
    
    for hp in hp_list_old:
        if hp > 1:
            hp_list_new.extend([int(hp/2), int(hp/2)])
            count_attack_new += 1
        elif hp == 1:
            count_attack_new += 1
    return hp_list_new, count_attack_new


hp_list_now = [H]
count_attack_now = 0

# 倒していないモンスターが居続ける限り実行
while hp_list_now != []:
    hp_list_new, count_attack_new = attack(hp_list_now, count_attack_now)
    hp_list_now, count_attack_now = hp_list_new, count_attack_new

print(count_attack_now)

Submission status: Time Limit Exceeded

Solution code:
H=int(input())
from collections import deque
stack=deque([H])
ans=0
while stack:
    ans+=1
    x=stack.pop()
    if x>1:
        stack.append(x//2)
        stack.append(x//2)
    else:
        continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

# input
H = int(input())

M = [H]
cnt = 0

while [1] * len(M) != M:
    for m, count in Counter(M).items():
        M = [m // 2] * (2 * count)
        cnt += count

print(cnt + len(M))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

# input
H = int(input())

M = [H]
cnt = 0

while [1] * len(M) != M:
    target = [m for m in M if m > 1]
    for m, count in Counter(target).items():
        M = [
            hp
            for hp in M + [m // 2] * (2 * count)
            if hp != m
        ]
        cnt += count

print(cnt + len(M))

Submission status: Time Limit Exceeded

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)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from collections import deque

# 入力を整数に変換して受け取る
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()))


monster = deque()
def main():
    h = input_int()

    monster.append(h)

    cnt = 0
    while len(monster) != 0:
        cnt += 1
        temp = monster.popleft()
        if temp != 1:
            val = temp // 2
            monster.append(val)
            monster.append(val)

    return cnt


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

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

cnt = 0

ans = 1
while True:
    H = int(H / 2)
    cnt += 1
    ans *= 2
    if H ==1:
        break
cnt += 1
ans *= 2

print(ans-1)

Submission status: Time Limit Exceeded

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

cnt = 0

ans = 1
while True:
    H = math.floor(H/2)
    cnt += 1
    ans *= 2
    if H ==1:
        break
cnt += 1
ans *= 2

print(ans-1)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

i = 1
sm = 1

while 1:
    H = H // 2

    sm += 2**i
    i += 1

    if H == 1:
        break

print(sm)

Submission status: Time Limit Exceeded

Solution code:

import math
H = int(input())


def iterated_power(z: int, n: int, mod=None) -> int:
    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

cnt = 0
while True:
    H = math.floor(H/2)
    cnt += 1
    if H ==1:
        break
cnt += 1

ans = iterated_power(2, cnt) - 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import queue

h = int(input())
q = queue.Queue()

count = 0
q.put(h)
while(True):
    if(q.empty()):
        break

    x = q.get()
    if(x == 1):
        count = count + 1
    else:
        q.put(x//2)
        q.put(x//2)
        count = count + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

from collections import deque

d = deque([H])

count = 0
sm = 0
while 1:
    H //= 2
    count += 1
    sm += 2**count

    if H == 1:
        break

print(sm+1)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
h = [int(input())]
counter = 0
while True:
    if(h == []):
        print(counter)
        break
    t = h[0]
    h = ([t / 2, t / 2] if t / 2 >= 1 else []) + h[1:]
    counter += 1

Submission status: Time Limit Exceeded

Solution code:
zettaiTLE = int(input())
M = [zettaiTLE]                
cnt = 0
while True:
  if M[0] == 1:
    del M[0]
    if len(M) == 0:
      cnt += 1
      print(cnt)
      exit()
  else :
    tekito = M[0]
    del M[0]
    for i in range(2):
      M.append(tekito // 2)
  cnt += 1

Submission status: Time Limit Exceeded

Solution code:
h = int(input())


li = list()
ans = 0
def dfs(x):
    global ans
    ans += 1
    if x == 1:
        return
    else:
        dfs(x//2)
        dfs(x//2)

dfs(h)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
count = 0
P = [H]
while H > 0:
  H //= 2
  P.pop(0)
  P.append(H)
  P.append(H)
  H = P[0]
  count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# モンスターの体力H
H = int(input())
monster = []
monster.append(H)

# HP1ならヤる.1より大きいならHP半分にして分裂
count = 0
while True:
  if monster == []:
    break
  if monster[0] > 1:
    a = monster[0] // 2
    monster.pop(0)
    monster.append(a)
    monster.append(a)
    count += 1
  elif monster[0] == 1:
    monster.pop(0)
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

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

r = func(H)
print(r)

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
count = 0
def dfs(h):
    global count
    if h == 1:
        count += 1
    else:
        count += 1
        if h%2 == 0:
            dfs(h/2)
            dfs(h/2)
        else:
            dfs((h-1)/2)
            dfs((h-1)/2)

dfs(h)
print(count)

Submission status: Time Limit Exceeded

Solution code:
H=int(input())
import copy
List=[]
while True:
    H=H+1
    if H%2==0:
        List.append(H)
        l=copy.deepcopy(List)
        h=l[0]
        while h%2==0:
            h=h/2
            if h==1:
                print(H-1)
                exit()
            else:
                List.clear()
                l.clear()
    else:
        pass

Submission status: Time Limit Exceeded

Solution code:
h = int(input())
new_h = h
pow_num = 0
ans = 0
attack = 1
preattack = 1


while(1):
  new_h = new_h//2
  pow_num += 1
  if new_h == 1:
    break
for i in range(pow_num):
  preattack = preattack*2
  attack += preattack
print(attack)

Submission status: Time Limit Exceeded

Solution code:
j = 1
a = 1
i = int(input())

while i != 1.0:
    i /= 2
    j *= 2
    a += j

print(a)

Submission status: Time Limit Exceeded

Solution code:
import sys
H = sys.stdin.readline()
H = int(H)

count = 0
roop_c = 2
while True:
    H = H // 2
    count += roop_c
    roop_c *= 2

    if H == 1:
        break

print(count+1)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

count = 0
roop_c = 2
while True:
    H = H // 2
    count += roop_c
    roop_c *= 2

    if H == 1:
        break

print(count+1)

Submission status: Time Limit Exceeded

Solution code:
H = int(input())

roop_c = 2
monster_hp = [H]
while True:
    value = monster_hp[-1] // 2
    for _ in range(roop_c):
        monster_hp.append(value)
    roop_c *= 2

    if monster_hp[-1] == 1:
        break

print(len(monster_hp))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
N2 = N
count = 0
i = 1

while True:
  if N == i:
    break
  i *= 2
  count += N2
  N2 //= 2

print(count + 1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
enm = [n]
def ap(lst, item):
  lst = lst.append(item)
  return lst
cnt = 0

while enm != []:
  a = enm[0]
  del enm[0]
  if a == 1:
    pass
  else:
    b = int(a / 2)
    ap(enm, b)
    ap(enm, b)
  cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
 
h = float(input())
enemies = [h]
 
count = 0
while len(enemies) > 0:
  temp = []
  for enemy in enemies:
    count+=1
    if enemy > 1:
      temp.append(math.floor(enemy / 2))
      temp.append(math.floor(enemy / 2))
  enemies = temp

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(2000000000)

h = int(input())

attack = 0
mons_hp_list = []
mons_hp_list.append(h)

def a(mons_hp_list, attack):
  strongest = max(mons_hp_list)
  attack += 1
  if strongest == 1:
    del mons_hp_list[mons_hp_list.index(strongest)]
  else:
    del mons_hp_list[mons_hp_list.index(strongest)]
    mons_hp_list.append(strongest//2)
    mons_hp_list.append(strongest//2)
  if len(mons_hp_list) == 0:
    print(attack)
    return attack
  a(mons_hp_list, attack)
a(mons_hp_list, attack)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
H = int(input())
n = 0
monsters = [H]
while len(monsters) > 0:
    n += 1
    HH = monsters[0] // 2
    if HH > 0:
        monsters.extend([HH, HH])
    del monsters[0]

print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3
H = int(input())

h = H
n = 1
while h != 2 and h != 3:
    n *= 2
    h = h // 2
print(4 * n - 1)

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3
H=int(input())
h = H
n = 1
while h != 2 and h != 3:
    n *= 2
    h = h//2
print( 4 * n - 1 )