def rec(history, maxdepth, res):
    if len(history)<maxdepth:
        #print (history)
        last=history[-1]
        if res[last[0]] == 0 or res[last[0]] > 3+len(history):
            res[last[0]] = 3+len(history)
        
        if last[3][0] != 's' and last[1] > 0:
            next=(last[1], last[0], 0, 's1')
            rec(history + [next], maxdepth, res)
        if last[2] > 0:
            next=(last[2], last[0], 0, 's2')
            rec(history + [next], maxdepth, res)
        if last[0] % 2 == 0:
            next=(int(last[0]/2), last[1]+int(last[0]/2), last[2]+int(last[0]/2), 'f')
            rec(history + [next], maxdepth, res)
    else:
        print('stopped')

maxpower = 128
maxdepth = 17
power = 2
res = [0]*(maxpower+1)
while power <= maxpower:
    rec([(power, 0, 0, '-')], maxdepth, res)
    power *= 2

print('n 2n-1 => res')
for n in range(2, int(maxpower/2)+1):
    print (n, 2*n-1, '=>', res[2*n-1])
