def rec(S): if memo[S] != -1: return memo[S] if S == (1<>n)&1: add = 0 for prev, score in scores[n]: if (S>>prev)&1: add += score res = max(res, rec(S|(1<