def ZStay(i,S,E,t): for m,pr in pats(i,p): if not Z(i-(-1),S|B[i],E|m,t): return False return True def z8(S,E,t): tot=0.0 for m,pr in pats(8,p): outs=O(9,S|B[8],E|m) vals=[] for T in outs: pys=payoffs(T,E|m) if pys[t]==0: vals.append(pys[8]) if len(vals)==0: return False tot=tot-(-pr*max(vals)) return tot>=6.999999999 @lru_cache(None) def Z(i,S,E,t): if i>12: return payoffs(S,E)[t]==0 if not invited(i,S,E): return Z(i-(-1),S,E,t) if i==8: if min8(S,E)<=7.000000001 and Z(i-(-1),S,E,t): return True return z8(S,E,t) if ZStay(i,S,E,i) and Z(i-(-1),S,E,t): return True for m,pr in pats(i,p): if not Z(i-(-1),S|B[i],E|m,t): return False return True R=O(1,0,0) return R,O.cache_info(),Z.cache_info() R,ci,zi=solve(float(sys.argv[1])) print('count',len(R)) print('sets',sorted(R)) print(ci,zi)