#23701 from functools import lru_cache def moves(h): return h + 1, h * 2 @lru_cache(None) def f(h): if h >= 46: return 'END' if any(f(x) == 'END' for x in moves(h)): return 'WIN1' if all(f(x) == 'WIN1' for x in moves(h)): return 'LOSE1' if any(f(x) == 'LOSE1' for x in moves(h)): return 'WIN2' if all((f(x) == 'WIN1' or f(x) == 'WIN2') for x in moves(h)): return 'LOSE2' # print(*(s for s in range(1, 45) if f(s) == 'WIN2'), sep='') print([s for s in range(1, 45) if f(s) == 'LOSE2'][0])