python3 - <<'EOF' from functools import lru_cache V=[[10,5,4],[10,8,6],[10,8],[10,3]] L=[len(x) for x in V] @lru_cache(None) def f(st,t): moves=[] for i,(p,q) in enumerate(st): if p=='U': moves.append((i,('A' if t==0 else 'B',1))) elif p=='A' or p=='B': if q