for Y in C: pm=Y[0]+Y[1] px=Y[-2]+Y[-1] o=[k for k in range(3) if k!=i] for j,(jl,jr) in enumerate(I): for tv in range(px-jr,pm-jl+1): t=tv%p B=allow(Y,t,I[o[0]]) if not B:continue D=allow(Y,t,I[o[1]]) if not D:continue for b in B: for c in D: if inV((b+c)%p,t): S=set(Y) S.add(b) S.add(c) if len(S)==50 and t not in S: print('FOUND',i,len(Y),j,t,b,c,Y[0],Y[-1],flush=True) raise SystemExit print('done')